iOS中UILabel text两边对齐的实现代码
程序员文章站
2023-12-21 13:49:46
废话不多说了,直接给大家贴代码了,具体代码如下所示:
-(nsattributedstring *)settextstring:(nsstring *)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两边对齐的实现代码,希望对大家有所帮助