本文通过一段实例代码给大家介绍了ios中uilabel text两边对齐的实现方法,非常不错,具有参考借鉴价值,需要的朋友参考下
废话不多说了,直接给大家贴代码了,具体代码如下所示:
-(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中UILabel text两边对齐的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程学习网网站的支持!
沃梦达教程
本文标题为:iOS中UILabel text两边对齐的实现代码


猜你喜欢
- Android实现监听音量的变化 2023-03-30
- Android实现轮询的三种方式 2023-02-17
- 最好用的ios数据恢复软件:PhoneRescue for Mac 2023-09-14
- 详解flutter engine 那些没被释放的东西 2022-12-04
- Flutter实现底部和顶部导航栏 2022-08-31
- iOS 对当前webView进行截屏的方法 2023-03-01
- 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14
- Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
- Android studio实现动态背景页面 2023-05-23
- SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02