關於UILabel行高自適應的方法

2021-07-15 17:03:20 字數 810 閱讀 2147

關於uilabel行高根據內容自適應,**如下:

uilabel *label = [[uilabel alloc] init];

label.font = [uifont systemfontofsize:14];

label.numberoflines = 0;

nsstring *string;

string = @"人生是一場旅程。我們經歷了幾次輪迴,才換來這個旅程。而這個旅程很短,因此不妨大膽一些,不妨大膽一些去愛乙個人,去攀一座山,去追乙個夢……有很多事我都不明白。但我相信一件事。上天讓我們來到這個世上,就是為了讓我們創造奇蹟。——《大魚海棠》";

cgsize labelsize = [string boundingrectwithsize:cgsizemake([uiscreen mainscreen].bounds.size.width, maxfloat) options:nsstringdrawinguseslinefragmentorigin attributes:@ context:nil].size;

cgrect labelrect = cgrectmake(0, 20, labelsize.width, labelsize.height);

label.text = string;

label.frame = labelrect;

[self.view addsubview: label];

執行結果如圖:

Java POI Excel 行高自適應

在excel處理的過程中,可能有需要用到行高自適應的時候。下面貼出用poi實現excel行高自適應的 該 可以處理一行excel按內容自適應高度。可以處理合併單元格。上 根據行內容重新計算行高 param row public static void calcandsetrowheigt hssfr...

iReport自適應行高

ireport設計報表,當detail的行高需要自適應時,應按如下設定 1.所有textfield的 position type fix relative to top 或fix relative to bottom 2.所有textfield的 stretch type relative to b...

UILabel的自適應長度

這個frame是無所謂的,後面還會重新設定它的size。uilabel label uilabel alloc initwithframe cgrectmake 0,0,0,0 label.numberoflines 0 建立乙個字型大小的字典 nsdictionary attributes nss...