栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > iOS

iOS中UILabel text两边对齐的实现代码

iOS 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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两边对齐的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对考高分网网站的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/166907.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号