iOS基本控件之UISegmentrol

在項(xiàng)目中,我們狠容易遇到就是一些產(chǎn)品,他們什么也不懂,還就是喜歡瞎搞,比如說蘋果原生的UISegmentrol ,產(chǎn)品要求我們怎么怎么做,沒辦法,誰讓人家是產(chǎn)品呢,

于是我就只能看這個(gè)UISegmentrol的官方文檔了,看一遍不知道怎么修改,從頭到尾細(xì)致地看了兩遍,終于知道怎么弄了,

要的是這樣的一個(gè)效果,通過看官方的API,找到了答案,文檔上是這么說的:

/*

You may specify the font, text color, and shadow properties for the title in the text attributes dictionary, using the keys found in NSAttributedString.h.

*/

- (void)setTitleTextAttributes:(nullable NSDictionary *)attributes forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

- (nullable NSDictionary *)titleTextAttributesForState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

看到上邊這幾句話,我頓時(shí)眼前一亮,馬上code就出來了,效果也就自然而然形成,code如下:

//修改系統(tǒng)的UISegmentControl

UIColor *textColor = PB_COLOR_18;//black

NSDictionary *textColorDic = [NSDictionary dictionaryWithObject:textColor forKey:NSForegroundColorAttributeName];

[segmentControl setTitleTextAttributes:textColorDic forState:UIControlStateNormal];

UIColor *selectTextColor = PB_COLOR_1;//blue

NSDictionary *selectTextColorDic = [NSDictionary dictionaryWithObject:selectTextColor forKey:NSForegroundColorAttributeName];

[segmentControl setTitleTextAttributes:selectTextColorDic forState:UIControlStateSelected];

OK。解決

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容