想法简友广场

iOS UILable的分类

2022-08-15  本文已影响0人  海边的遐想

在做项目的时候我们会经常遇到label的中划线/下划线/修改行行间距/修改字间距的问题
/// 中划线
/// @param text 字符
/// @param color 颜色
-(void)setMiddlelineStyleSingle:(NSString *)text color:(UIColor *)color{
//添加中划线
if (!LMStringIsEmpty(text))
{
NSDictionary * centerAttribtDic = @{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle],NSForegroundColorAttributeName:color};
NSMutableAttributedString * centerAttr = [[NSMutableAttributedString alloc] initWithString:text attributes:centerAttribtDic];
self.attributedText = centerAttr;
}
}
/// 下划线
/// @param text 字符
/// @param color 颜色
-(void)setUnderlineStyleSingle:(NSString )text color:(UIColor )color {
//添加下划线
if (!LMStringIsEmpty(text))
{
NSDictionary * underAttribtDic = @{NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle],NSForegroundColorAttributeName:color};
NSMutableAttributedString * underAttr = [[NSMutableAttributedString alloc] initWithString:text attributes:underAttribtDic];
self.attributedText = underAttr;
}
}
/

上一篇 下一篇

猜你喜欢

热点阅读