【问题标题】:make UILabel's text bold使 UILabel 的文本加粗
【发布时间】:2011-06-03 21:46:36
【问题描述】:

我想让 UILabel 的文字加粗

infoLabel=[[UILabel alloc]initWithFrame:CGRectMake(90,150, 200, 30)];
[infoLabel setText:@"Drag 14 more Flavors"];
[infoLabel setBackgroundColor:[UIColor clearColor]];
[infoLabel setFont:[UIFont fontWithName:@"Arial" size:16]];

[infoLabel setTextColor:[UIColor colorWithRed:193.0/255 
                                        green:27.0/255 
                                         blue:23.0/255 
                                        alpha:1 ]];

【问题讨论】:

    标签: ios objective-c uilabel uifont textcolor


    【解决方案1】:

    我建议在可能的情况下使用动态字体大小为您的用户提供尽可能好的可访问性。

    您可以通过执行以下操作使标签使用系统动态字体并将其设置为粗体:

     exampleLabel.font = UIFont.preferredFont(forTextStyle: .body, compatibleWith: UITraitCollection(legibilityWeight: .bold))
    

    【讨论】:

    • 我只是为了好玩才尝试这个...没有用。
    【解决方案2】:

    对于快速用户来说,这应该可以工作:

    myLabel.font = UIFont.boldSystemFont(ofSize: 12.0)
    

    或者如果您想使用不同的字体:

    myLabel.font = UIFont(name:"HelveticaNeue-Bold", size: 12.0)
    

    【讨论】:

      【解决方案3】:

      在 Xcode 中使用 GUI 选择标签,然后转到 Attributes Inspector。选项之一是字体。单击字体图标(不是上下箭头)。在出现的弹出窗口中展开字体组合框。在粗体系统部分下选择常规。

      【讨论】:

        【解决方案4】:

        如果您没有自定义字体的粗体变体,您可以将笔画设置为负值以产生粗体效果。见这里:

        How can I both stroke and fill with NSAttributedString w/ UILabel

        【讨论】:

          【解决方案5】:

          如果要保留系统字体并加粗:

          [infoLabel setFont:[UIFont boldSystemFontOfSize:16]];
          

          【讨论】:

          • 如果要保留大小:[infoLabel setFont:[UIFont boldSystemFontOfSize: infoLabel.font.pointSize]];
          【解决方案6】:

          试试

          [infoLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:16]];
          

          检查您尝试使用的字体是否在设备上可用也是值得的

          【讨论】:

          • 最好将此答案与以下答案合并:如果您想保留系统字体并将其设为粗体:[infoLabel setFont:[UIFont boldSystemFontOfSize:16]];
          猜你喜欢
          • 1970-01-01
          • 2016-05-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-04-15
          • 2020-04-27
          • 2016-06-07
          • 2014-01-25
          相关资源
          最近更新 更多