【问题标题】:iPhone Dividing string into multi line and display as LabeliPhone将字符串分成多行并显示为标签
【发布时间】:2011-10-20 13:10:23
【问题描述】:

我有一个字符串如下:

#define BEEF_LABLE @"Recommended Internal Temp 145 - Medium Rare 160 - Medium 170 - Well done"

我想在 4 行标签中显示它。第一行是“建议内部温度”,第二行是“145 - 中等稀有”,第三行是“160 - 中等”,第四行是“170 - 做得好”。

如何相应地拆分文本。

【问题讨论】:

    标签: iphone ios nsstring uilabel


    【解决方案1】:
    yourLabel.lineBreakMode = UILineBreakModeWordWrap;
    yourLabel.numberOfLines = 0;  
    

    并相应地在字符串中添加 ("\n") ......就像这样

    #define BEEF_LABLE @"Recommended Internal Temp \n 145 - Medium Rare 160 \n- Medium \n 170 - Well done"
    

    【讨论】:

    • +1 我通常使用 \r\n 来分行。只是 \n 有诀窍吗?此外,设置youLabel.numberOfLines = 0; 是如何告诉 UILabel 有任意数量的行。 Trisha 我肯定知道这一点,但我将其添加到此评论中,因为该行正在做什么并不明显。也可以考虑看看Multiple lines of text in UILabel
    猜你喜欢
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    相关资源
    最近更新 更多