当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS中UILabel text两边对齐的实现代码

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

2019年07月24日  | 移动技术网移动技术  | 我要评论

废话不多说了,直接给大家贴代码了,具体代码如下所示:

-(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两边对齐的实现代码,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网