【问题标题】:How to decrease the UIFont size and show large sentence one line UILabel iPhone?如何减小 UIFont 大小并显示大句一行 UILabel iPhone?
【发布时间】:2012-07-19 08:56:01
【问题描述】:

我的 iPhone 应用中有一个 UILabel。我想在一行中显示 UILabel 中的大句子。这意味着我想减小字体大小并在可见区域显示全文。我不想在多行中显示它。谁能帮我做到这一点?

我的代码是:

textViewLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 5, 194, 20)];
textViewLabel.text = @"I have an UILabel in my iPhone app. I have want";
textViewLabel.textColor = [UIColor lightGrayColor];
textViewLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
textViewLabel.numberOfLines = 0;
textViewLabel.backgroundColor = [UIColor clearColor];

CGSize maximumLabelsize2 = CGSizeMake(194,20);
CGSize expectedLabelsize2 = [result sizeWithFont:textViewLabel.font constrainedToSize:maximumLabelsize2 lineBreakMode:textViewLabel.lineBreakMode]; 
CGRect messagesFrame = textViewLabel.frame;
messagesFrame.size.height = expectedLabelsize2.height;
textViewLabel.frame = messagesFrame; 

有人请帮我做这件事吗?提前致谢。

【问题讨论】:

标签: iphone ios fonts uilabel


【解决方案1】:

更改 numberOfLines 属性
textViewLabel.numberOfLines = 0; // 0 means as many lines as needed

textViewLabel.numberOfLines = 1;

添加

textViewLabel.adjustsFontSizeToFitWidth = YES; 

考虑设置

textViewLabel.minimumFontSize = someValue; // default is 0.0

【讨论】:

    【解决方案2】:

    试试这个属性:

    myLabel.adjustsFontSizeToFitWidth = YES;
    

    【讨论】:

      【解决方案3】:

      试试这个:

      [textViewLabel  setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-03-11
        • 1970-01-01
        • 2011-08-05
        • 1970-01-01
        • 1970-01-01
        • 2019-11-30
        • 2010-09-28
        • 1970-01-01
        相关资源
        最近更新 更多