温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

iOS中如何实现UILabel text两边对齐

发布时间:2021-07-09 09:11:55 来源:亿速云 阅读:168 作者:小新 栏目:移动开发

小编给大家分享一下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两边对齐”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ios
AI