iOS 設定行間距

2021-07-13 20:26:24 字數 1260 閱讀 5574

uilabel設定行間距:

uilabel

*bodylabel = [

uilabel 

new];

bodylabel.

frame

=cgrectmake(0

, 0, self

.view

.dd_w

, 120

);bodylabel.

text

=@"有人說,生活如水,何必要顛簸出浪花,最後,濺了自己一身水,平平淡淡才是真。但我其實並不這樣認為,生活雖然只是一杯無味的水,但如果我們添一些「調味劑」呢!如果你努力工作,揮灑汗水,就一定會收穫一杯香甜的水。但如果你懶惰貪婪,不久疾病就會在你身上永不離身,自然就會得到一杯苦澀的了。";[

self

.view

addsubview

:bodylabel];

nsmutableattributedstring

*attribute = [[

nsmutableattributedstring 

alloc

] initwithstring

:bodylabel

.text

];nsmutableparagraphstyle

*paragrap = [[

nsmutableparagraphstyle 

alloc

] init

];[paragrap 

setlinespacing

:10.5f

]; // 行間距高度

nsrange

range =

nsmakerange

(0.f

,  [

bodylabel

.text

length

]);[attribute 

addattribute

:nsparagraphstyleattributename

value

:paragrap

range

:range];

[bodylabel 

setattributedtext

:attribute];

[bodylabel 

setfont

:[uifont

systemfontofsize:12

]];[

bodylabel 

sizetofit

];

View TextView行間距設定

1 設定行間距 android linespacingextra,取值範圍 正數 負數和0,正數表示增加相應的大小,負數表示減少相應的大小,0表示無變化。android id id txt msg android layout width wrap content android layout he...

Android TextView 設定行間距字間距

行間距 android textview 設定行間距的相對來說比較簡單,可以通過設定textview的android linespacingextra或android linespacingmultiplier來達到你希望看到的結果。android linespacingextra 設定行間距 如下...

Flutter text設定行間距

通過設定 strutstyle 的 leading 然後利用 transform 做計算翻方向位置偏移,因為 leading 是上下均衡的,所以計算後就可以得到我們所需要的行間距大小。雖然無法保證一定 100 畫素準確,你是否還知道其他方法?transform.translate offset of...