UITextView text cut off when there is a large amount of text

前端 未结 3 1195
独厮守ぢ
独厮守ぢ 2021-01-13 19:17

I have a UITableViewCell subclass that contains a UITextView where scrolling is turned off. I set its frame like this, in my table view cell layoutSubviews method:



        
相关标签:
3条回答
  • 2021-01-13 19:24

    According to this and similar answers, the problem could be that "the correct contentSize is only available after the UITextView has been added to the view ... Prior to that it is equal to frame.size"

    I'd suggest you to calculate the height in a different way, like -sizeWithFont: or -sizeTofit

    0 讨论(0)
  • 2021-01-13 19:43

    I had the same issue and resolved it working on the textView padding (in swift5):

    yourTextView.textContainerInset = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)

    Hope it can help :)

    0 讨论(0)
  • 2021-01-13 19:49

    Use this to get the textSize

    // find the text width; so that btn width can be calculate
    CGSize textSize = [@"YOUR TEXT" sizeWithFont:[UIFont fontWithName:@"Arial" size:20.0] 
                                  constrainedToSize:CGSizeMake(320.0f, 99999.0f)
                                      lineBreakMode:UILineBreakModeWordWrap];
    

    and then set height using this as :

    CGRect frame = self.bodyTextView.frame;
    
    frame.size = textSize;
    self.bodyTextView.frame = frame;
    

    Hope it helps you.

    0 讨论(0)
提交回复
热议问题