ios Label上顯示不同顏色文字

2021-08-07 01:30:53 字數 523 閱讀 5094

//直接貼上**即可用,這個是封裝好的乙個方法

//str是不需要改變的顏色,這個是自己設定lable的字型顏色

//string傳的是需要改變字型顏色的字串,這個是需要改變字串的顏色

//color是需要改變的顏色

- (nsmutableattributedstring *)stringcolorstr:(nsstring *)str string:(nsstring *)string color:(uicolor*)color

//呼叫方法

nsstring *totalstr = @"這個是不需要改變顏色的字串";

nsstring *totalstr1 = @"這個是你要改變顏色的字串";

[self

.totallabel setattributedtext:[rrpprintobject stringcolorstr:totalstr string:totalstr1 color:iwcolor(50, 50, 50)]];

iOS label設定不同的字型 顏色

uilabel lable uilabel alloc initwithframe cgrectmake 0,70,320,40 lable.numberoflines 0 lable.backgroundcolor uicolor greencolor self.view addsubview l...

iOS開發 label上顯示不同顏色不同大小的字

1 要顯示不同顏色的數字 nsstring numberstr nsstring stringwithformat d 121 myabel建立的label myabel setattributedtext self attrstrfrom nsstring stringwithformat 已有 ...

UILabel顯示不同的字型和顏色

在專案開發中,我們經常會遇到在這樣一種情形 在乙個uilabel 使用不同的顏色或不同的字型來體現字串,在ios 6 以後我們可以很輕鬆的實現這一點,官方的api 為我們提供了uilabel類的attributedtext,使用不同顏色和不同字型的字串,我們可以使用nsattributedtext ...