在UITextView中调整linespacing

时间:2011-06-15 10:36:56

标签: iphone xcode uitextview

在iPhone应用程序中是否有任何方法可以调整UITextview中行之间的行间距。

提前致谢。

2 个答案:

答案 0 :(得分: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];

答案 1 :(得分:-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;