2011-06-15 79 views
2

iphone應用程序中是否有任何方式來調整UITextview中行間的行距。在UITextView中調整行間距

在此先感謝。

+0

[在UITextView中設置行高(可能重複http://stackoverflow.com/questions/3760924/set-line-height-in- uitextview) – 2011-06-15 11:39:02

回答

-1

這完美的作品對我來說:

#define MAX_HEIGHT 2000  
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14] 
       constrainedToSize:CGSizeMake(100, MAX_HEIGHT) 
        lineBreakMode:UILineBreakModeWordWrap]; 

[textview setFont:[UIFont systemFontOfSize:14]]; 
[textview setFrame:CGRectMake(45, 6, 100, size.height + 10)]; 
textview.text = text; 
+0

太棒了,謝謝,儘管幾個月後.. – 2012-02-28 04:16:32

+3

這實際上並沒有回答被問到的問題。 – 2013-01-09 19:22:19

0
 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; 
     paragraphStyle.lineHeightMultiple = 50.0f; 
     paragraphStyle.maximumLineHeight = 50.0f; 
     paragraphStyle.minimumLineHeight = 50.0f; 
     NSString *string = @"if you want reduce or increase space between lines in uitextview ,you can do this with this,but donot set font on this paragraph , set this on uitextveiw."; 

     NSDictionary *ats = @{ 
     NSParagraphStyleAttributeName : paragraphStyle, 
     }; 

     [textview setFont:[uifont fontwithname:@"Arial" size:20.0f]]; 
     textview.attributedText = [[NSAttributedString alloc] initWithString:string attributes:ats];