效果圖
後乙個文字是前乙個文字的後面
self
.namelb
= [[
uilabel
alloc
]init];
self
.namelb
.numberoflines=0
; self
.namelb
.backgroundcolor
= [uicolor
redcolor];
[self
.view
addsubview
:self
.namelb];
self
.agelb
= [[
uilabel
alloc
]init];
self
.agelb
.numberoflines=0
; self
.agelb
.backgroundcolor
= [uicolor
greencolor];
[self
.view
addsubview
:self
.agelb];
nsstring
* str1 =
@"這是乙個測試資料";
nsstring
* str21 =
@"我也是乙個測試資料";
uifont
*font = [
uifont
fontwithname
:@"arial"
size:14
]; //設定乙個行高上限
cgsize
size =
cgsizemake
(375
,2000);
//計算實際
frame
大小,並將
label
的frame
變成實際大小
cgsize
labelsize = [str1
sizewithfont
:font
constrainedtosize
:size
linebreakmode
:uilinebreakmodewordwrap];
self
.namelb
.font
= font;
self
.namelb
.text
= str1; [
self
.namelb
setframe
:cgrectmake(13
,100
, labelsize.
width
, labelsize.
height
)];
nslog
(@"labelsize--%@"
,nsstringfromcgsize
(labelsize));
cgsize
labelsize2 = [str21
sizewithfont
:font
constrainedtosize
:size
linebreakmode
:uilinebreakmodewordwrap];
self
.agelb
.font
= font;
self
.agelb
.text
= str21;
cgfloat
x1 =
cgrectgetmaxx
(self
.namelb
.frame);
[self
.agelb
setframe
:cgrectmake
(x1,
100, labelsize2.
width
, labelsize2.
height
)];
WebView寬度自適應
webview寬度自適應 用webview元件顯示普通網頁時一般會出現橫向滾動條,這樣會導致頁面檢視起來非常不方便。其實通過設定websettings的屬性可以輕易地解決此問題,不過此設定隱藏的比較深,一般很少人會用到。12 websettings webview.getsettings webse...
寬度自適應布局
自適應布局是一種很常見的布局方式,現將常見的幾種實現方式列下 1 利用float 左右兩div分別左右浮動,不再占用文件流,塊元素div.main自動佔據整行,然後給main新增左右margin分別為左右兩塊元素的寬,如下 left right main 2 利用絕對定位 圖如上 左右兩個div分別...
WebView寬度自適應
用webview元件顯示普通網頁時一般會出現橫向滾動條,這樣會導致頁面檢視起來非常不方便。其實通過設定websettings的屬性可以輕易地解決此問題,不過此設定隱藏的比較深,一般很少人會用到。view code xml 1 2websettings webview.getsettings webs...