一.效果图
二.代码
- (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]; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!
网友评论