【问题标题】:UITableViewCell change font of delete row buttonUITableViewCell 更改删除行按钮的字体
【发布时间】:2014-11-29 21:00:37
【问题描述】:

是否可以自定义 UITableView 中删除按钮的字体?

【问题讨论】:

    标签: ios objective-c uitableview fonts


    【解决方案1】:

    不妨看看this question

    您可以使用具有所需字体的图像,然后将按钮设置为该图像。如果您使用不同的语言可能会出现问题

    【讨论】:

      【解决方案2】:

      UITableViewCell的删除按钮使用系统字体。因此,如果您想更改应用中的系统字体,只需覆盖 -systemFontOfSize:(CGFloat)fontSize

      创建类别UIFont+System并将此代码放入.m

      #pragma clang diagnostic push
      #pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
      
      + (UIFont *)systemFontOfSize:(CGFloat)fontSize {
          return [UIFont fontWithName:@"NameOfYourFont" size:fontSize];
      }
      
      #pragma clang diagnostic pop
      

      【讨论】:

        【解决方案3】:

        你可以利用

        UIButton * buttonAppearance = [UIButton appearanceWhenContainedInInstancesOfClasses:@[[YourCustomCell class]]];
        [buttonAppearance setAttributedTitle: attributedString forState: UIControlStateNormal];
        

        注意:这会将标题设置为单元格中的所有按钮。然后,您可以根据需要进行更改。

        【讨论】:

        • 在 iOS 11 中似乎无法使用。不确定之前是否可以使用
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-27
        • 1970-01-01
        • 1970-01-01
        • 2013-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多