Attributes:文本属性 和NSAttributedString

前言:

  有一些控件无法直接设置文本大小,需要使用方法 setTitleTextAttributes 来设置文本属性

UIFont 字体样式 [UIFont fontWithName~];

iOS- 详解文本属性Attributes - 清澈Saup - 推酷

    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"任务" style:UIBarButtonItemStylePlain target:self action:@selector(clickRightBarItem)];
    [rightBarItem setTintColor:[UIColor blackColor]];
    [rightBarItem setTitleTextAttributes:@{
                  //1.设置字体样式:例如黑体,和字体大小
                  NSFontAttributeName:[UIFont fontWithName:@"Arial-BoldMT" size:15],
                  //2.设置段落样式
                  NSParagraphStyleAttributeName:[NSParagraphStyle defaultParagraphStyle],
                  //3.设置文字颜色
                  NSForegroundColorAttributeName:[UIColor redColor],
                  //4.设置背景颜色//下划线//空心字//删除线等等
                  NSBackgroundColorAttributeName:[UIColor greenColor]
                                           }forState:(UIControlStateNormal)];
   
原文地址:https://www.cnblogs.com/jiayongqiang/p/5570746.html