【问题标题】:adjusting linespacing in UITextView在 UITextView 中调整行距
【发布时间】:2011-06-15 10:36:56
【问题描述】:

在 iphone 应用程序中有什么方法可以调整 UITextview 中的行之间的行距。

提前致谢。

【问题讨论】:

标签: iphone xcode uitextview


【解决方案1】:
       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];

【讨论】:

    【解决方案2】:

    这对我来说非常适合:

    #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;
    

    【讨论】:

    • 这实际上并没有回答所提出的问题。
    猜你喜欢
    • 2014-10-10
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多