#define linespace 20
uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(0, 100, 320, 200)];
[label setbackgroundcolor:[uicolor blackcolor]];
[label settextcolor:[uicolor whitecolor]];
[label setnumberoflines:0];
nsstring *labeltext = @"可以自己按照寬高,字型大小,來計算有多少行。。然後。。。每行畫乙個uilabel。。高度自己可以控制把這個寫乙個自定義的類。 ";
nsmutableattributedstring *attributedstring = [[nsmutableattributedstring alloc] initwithstring:labeltext];
nsmutableparagraphstyle *paragraphstyle = [[nsmutableparagraphstyle alloc] init];
[paragraphstyle setlinespacing:linespace];//調整行間距
[attributedstring addattribute:nsparagraphstyleattributename value:paragraphstyle range:nsmakerange(0, [labeltext length])];
label.attributedtext = attributedstring;
[self.view addsubview:label];
[label sizetofit];
關於UILabel行高自適應的方法
關於uilabel行高根據內容自適應,如下 uilabel label uilabel alloc init label.font uifont systemfontofsize 14 label.numberoflines 0 nsstring string string 人生是一場旅程。我們經歷...
iOS開發 UILabel根據內容自動調整高度
寫法一 物件方法,傳入 字型 最大尺寸.即可得到寬高,最大尺寸主要限制寬度,如果是一行就給個 如果是多行就限制x值,y值隨便給 cgsize sizewithfont uifont font maxsize cgsize maxsize return self boundingrectwithsiz...
iOS開發調整UILabel的行間距
最近再做乙個專案時,發現uilabel中text的系統預設行間距不能滿足要求,於是在網上找到了調整行間距的 跟大家分享一下,希望能對你有所幫助。cgfloat heih 20 nsstring clabelstring 這是測試uilabel行間距的text。這是測試uilabel行間距的text。...