【问题标题】:how to change font of textfield after click on a bold button单击粗体按钮后如何更改文本字段的字体
【发布时间】:2016-06-18 06:24:57
【问题描述】:

我在设置文本字段的字体时遇到问题。我做了一个粗体按钮。单击粗体按钮后,整个文本字段字符串字体设置为粗体。但我只希望那些在按下粗体按钮后输入的单词变得粗体。

【问题讨论】:

  • 你应该使用NSMutableAttributedString
  • NSAttributedString *strAttributedTitle = [[NSAttributedString alloc] initWithString: attributes:@{NSForegroundColorAttributeName:[UIColor darkGrayColor],NSFontAttributeName:[UIFont fontWithName:@" Helvetica-Bold" 大小:15.0f]}];

标签: ios fonts uitextfield


【解决方案1】:

您需要在您的UITextView 中使用NSAttributedString。您必须记住粗体、非粗体文本的NSRange 以便进一步编辑。您需要的所有方法都可以在这里找到: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多