iOS中UILabel text两边对齐的实现代码
时间:2021-02-22 18:00:03|栏目:iOS代码|点击: 次
废话不多说了,直接给大家贴代码了,具体代码如下所示:
-(NSAttributedString *)setTextString:(NSString *)text
{ NSMutableAttributedString *mAbStr = [[NSMutableAttributedString alloc] initWithString:text];
NSMutableParagraphStyle *npgStyle = [[NSMutableParagraphStyle alloc] init];
npgStyle.alignment = NSTextAlignmentJustified;
npgStyle.paragraphSpacing = 11.0;
npgStyle.paragraphSpacingBefore = 10.0;
npgStyle.firstLineHeadIndent = 0.0;
npgStyle.headIndent = 0.0;
NSDictionary *dic = @{
NSForegroundColorAttributeName:[UIColor blackColor],
NSFontAttributeName :[UIFont systemFontOfSize:15.0],
NSParagraphStyleAttributeName :npgStyle,
NSUnderlineStyleAttributeName :[NSNumber numberWithInteger:NSUnderlineStyleNone]
};
[mAbStr setAttributes:dic range:NSMakeRange(0, mAbStr.length)];
NSAttributedString *attrString = [mAbStr copy];
return attrString;
}
NSString* const msg = @"6日,“幼儿园老师让带一条鱼”的微博突然间就火了!占领朋友圈!征服全国网友.图片甚至遭网友恶搞:水煮鱼、生鱼片都出来了。1月7日,记者在茫茫人海之中,历经千辛万苦终于在浙江慈溪找到了这位被网友吐槽的“粗心”家长!来听听他的解释吧";
self.lbView.attributedText = [self setTextString:msg];

栏 目:iOS代码
下一篇:轻松搞定iOS远程消息推送
本文标题:iOS中UILabel text两边对齐的实现代码
本文地址:http://www.codeinn.net/misctech/67666.html






