【问题标题】:how to set different font size to text of button name in storyboard如何在情节提要中为按钮名称的文本设置不同的字体大小
【发布时间】:2016-11-20 20:40:27
【问题描述】:

我想制作我想要制作登录屏幕的应用程序。它有一个名为“Log inn with Facebook”的按钮。我希望 Facebook 的字体大小大于登录方式。如何在主情节提要中设置它?谁能帮帮我?

【问题讨论】:

  • 选择要增加字体的文本。并在属性检查器中更改字体大小

标签: ios uibutton storyboard facebook-sdk-4.0


【解决方案1】:

按照这些步骤-

1.选择按钮

2.在属性检查器

中将其类型更改为自定义

3.将其标题从Plain改为Attributed

4.更改标题中要设置粗体的部分

【讨论】:

  • 已经这样做了,并且在故事板中运行良好。但如果我跑,它不会工作。还是纯文本。有什么想法吗?
  • 不,不要以编程方式触摸该按钮。
  • @SonicMaster 您将其设置为默认状态对吗?并且类型是自定义的?
  • 我删除按钮,重新添加并按照您的方式操作,它可以工作!谢谢@sanman!
【解决方案2】:

一种解决方案是使用带有两个不同UILabelUIView 作为子视图(您的“登录方式”标签和您的“Facebook”标签)。

然后,在UIView 上方,您可以有一个UIButton,其背景为白色,alpha 等于 0.01,因此按钮可以触摸但不可见。

这个UIButton 将是您用户界面的功能部分。

【讨论】:

    【解决方案3】:
    NSMutableAttributedString *titleText = [[NSMutableAttributedString alloc] initWithString:@"Login with Facebook"];
    [yourbutton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
    
    // Set the font to bold from the beginning of the string to the ","
    [titleText addAttributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName] range:NSMakeRange(0, 10)];
    
    
    // Set the attributed string as the buttons' title text
    [yourbutton setAttributedTitle:titleText forState:UIControlStateNormal];
    

    而不是创建 NSAttributedString 创建 NSMutableAttributedString 然后你可以像这样设置字符串。

    【讨论】:

      猜你喜欢
      • 2016-06-25
      • 2016-02-20
      • 2016-04-15
      • 2019-09-28
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多