17.属性字符串

2017-03-10  本文已影响8人  cj2527

设置多行文字,每行文字大小,颜色不一样,这个是比较常见的

1.导入YYKit框架

2.写代码


                   
                    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
                    style.lineSpacing = 3;//行距
                    //第一行的属性字符串
                    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString: @"立即支付" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.f],NSForegroundColorAttributeName:RGB(102, 102, 102),NSParagraphStyleAttributeName:style}];
                    //第二行的属性字符串
                    NSMutableAttributedString *attri2 = [[NSMutableAttributedString alloc] initWithString: @"\n(第二行)" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:8.f],NSForegroundColorAttributeName:RGB(102, 102, 102),NSParagraphStyleAttributeName:style}];
                    
                    [attri appendAttributedString:attri2];
                    self.payBtn.titleLabel.attributedText = attri;

                   self.payBtn.titleLabel.numberOfLines=0;
                   self.payBtn.titleLabel.textAlignment =NSTextAlignmentCenter;
上一篇 下一篇

猜你喜欢

热点阅读