2014-09-02 117 views

回答

0

1。根據文本和字體檢查UItextView大小:

// return the size for UITextView for both IOS7 and IOS6 
-(CGSize) getSizeWithMaxLabelSize:(CGSize) maxLabelSize forTextViewWithText:(NSString *) text 
{ 
CGSize expectedLabelSize; 
CGSize maximumLabelSize = maxLabelSize; 
if (SYSTEM_VERSION_GREATER_THAN(@"6.2")) { 
    NSDictionary *stringAttributes = [NSDictionary dictionaryWithObject:[UIFont fontWithName:@"Arial" size:EPCommentViewFontSize] forKey: NSFontAttributeName]; 
    CGRect rect =[text boundingRectWithSize:maximumLabelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:stringAttributes context:nil]; 
    expectedLabelSize = rect.size; 
    expectedLabelSize.height = ceilf(expectedLabelSize.height); 
    expectedLabelSize.width = ceilf(expectedLabelSize.width); 
} else { 
    expectedLabelSize = [text sizeWithFont:[UIFont fontWithName:@"Arial" size:EPCommentViewFontSize] constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping]; 
} 
    return expectedLabelSize; 
} 

2。將您的UITextView高度與expectedLabelSize.height進行比較以顯示或不是

3。更改UITextView frame.size.height觸摸視圖時更多

CGRect frame = _textView.frame; 
frame.size.height = [self getSizeWithMaxLabelSize:CGSizeMake(_textView.frame.size.height, NSIntegerMax) forTextViewWithText:_textView.text].height; 
_textView.frame = frame; 
+0

是的。我播下了這個答案。但是,如果這行中的文本不在行尾,我很感興趣如何計算更多按鈕的位置。 (例如:可能的解決方案是獲得uitextview中的最後一行寬度) – Devios 2014-09-02 11:43:20

+0

只是getSize到當前行 – 2014-09-02 12:11:36

相關問題