在項(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。解決