本宫不走寻常路,宝宝金水好吗,缘分吉他谱
txtlbl.font = [uifont boldsystemfontofsize:14.0f];
txtlbl.numberoflines = 0;
nsstring *str = @" 阿方决定设立科技特网络离开电视剧分w额两个大陆高科技了了不见了日i倒计时离开我说老师肯德基弗兰克萨江东父老将费德勒说阿方决定设立科技特网络离开电视剧分w额两个大陆高科技了了不见了日i倒计时离开我立科说老师肯德基弗兰克萨江东父老将费德勒说";
cgsize size = [str sizewithfont:txtlbl.font constrainedtosize:cgsizemake(txtlbl.frame.size.width, maxfloat) linebreakmode:nslinebreakbywordwrapping];
//根据计算结果重新设置txtlbl的尺寸
[txtlbl setframe:cgrectmake(7, 0, 310, size.height)];
txtlbl.text = str;
方法二:
// ios7_api_根据文字 字数动态确定label宽高
// 设置label的字体 helveticaneue courier
uifont *fnt = [uifont fontwithname:@"helveticaneue" size:24.0f];
_namelabel.font = fnt;
// 根据字体得到nsstring的尺寸
cgsize size = [_namelabel.text sizewithattributes:[nsdictionary dictionarywithobjectsandkeys:fnt,nsfontattributename, nil]];
// 名字的h
cgfloat nameh = size.height;
// 名字的w
cgfloat namew = size.width;
_namelabel.frame = cgrectmake(0, 0, namew,nameh);
方法三:
// 宽度w
cgfloat contentw = self.bounds.size.width - _content.frame.origin.x - kmargin;
// label的字体 helveticaneue courier
uifont *fnt = [uifont fontwithname:@"helveticaneue" size:18.0f];
_content.font = fnt;
_content.numberoflines = 0;
_content.linebreakmode = nslinebreakbywordwrapping;
// ios7中用以下方法替代过时的ios6中的sizewithfont:constrainedtosize:linebreakmode:方法
cgrect tmprect = [_content.text boundingrectwithsize:cgsizemake(contentw, 1000) options:nsstringdrawinguseslinefragmentorigin attributes:[nsdictionary dictionarywithobjectsandkeys:fnt,nsfontattributename, nil] context:nil];
// 高度h
cgfloat contenth = tmprect.size.height;
nslog(@"调整后的显示宽度:%f,显示高度:%f"contentw,contenth);
_content.frame = cgrectmake(0, 0, contentw,contenth);
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
-
-
iOS实现图片自动切换效果
本文实例为大家分享了ios实现图片自动切换的具体代码,供大家参考,具体内容如下#import "viewcontroller.h"#define imagevi...
[阅读全文]
-
-
-
-
-
-
网友评论