一.效果图

二.代码
?| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
- (void)viewdidload
{
[super viewdidload];
// do any additional setup after loading the view.
//根据内容自动调整高度
nsstring *str = @"公元前3000年,印度河流域的居民的数字使用就已经比较普遍,居民们采用了十进位制的计算法。";
uifont *font = [uifont systemfontofsize:13];
cgsize size = cgsizemake(200,2000);
cgrect labelrect = [str boundingrectwithsize:size options:(nsstringdrawinguseslinefragmentorigin|nsstringdrawingusesfontleading) attributes:[nsdictionary dictionarywithobject:font forkey:nsfontattributename] context:nil];
//uilabel
uilabel *label = [[uilabel alloc]initwithframe:cgrectmake(50,100, labelrect.size.width, labelrect.size.height)];
label.text = str;
label.backgroundcolor=[uicolor redcolor];
label.font = [uifont systemfontofsize:13];
label.numberoflines=0;
[self.view addsubview: label];
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。