iOS 13 UISegmentedControl適配

1、在iOS13中 毁渗,UISegmentedControl默認(rèn)樣式變?yōu)榘椎缀谧郑?/p>

iOS 13以上
iOS 13以下

實(shí)現(xiàn)延展 ,調(diào)用 segmentedIOS13Style方法

1、.h文件

@interface UISegmentedControl (Category)

- (void)segmentedIOS13Style;

@end

2倒信、.m文件

#import "UISegmentedControl+Category.h"

@implementation UISegmentedControl (Category)

- (void)segmentedIOS13Style {

? ? if (@available(iOS 13, *)) {

? ? ? ? UIColor *tintColor = [self tintColor];

? ? ? ? UIImage *tintColorImage = [self imageWithColor:tintColor];

? ? ? ? // Must set the background image for normal to something (even clear) else the rest won't work

? ? ? ? [self setBackgroundImage:[self imageWithColor:self.backgroundColor ? self.backgroundColor : [UIColor clearColor]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

? ? ? ? [self setBackgroundImage:tintColorImage forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

? ? ? ? [self setBackgroundImage:[self imageWithColor:[tintColor colorWithAlphaComponent:0.2]] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

? ? ? ? [self setBackgroundImage:tintColorImage forState:UIControlStateSelected|UIControlStateSelected barMetrics:UIBarMetricsDefault];

? ? ? ? [self setTitleTextAttributes:@{NSForegroundColorAttributeName: tintColor, NSFontAttributeName: [UIFont systemFontOfSize:13]} forState:UIControlStateNormal];

? ? ? ? [self setDividerImage:tintColorImage forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

? ? ? ? self.layer.borderWidth = 1;

? ? ? ? self.layer.borderColor = [tintColor CGColor];

? ? ? ? self.selectedSegmentTintColor = tintColor;

? ? }

}

- (UIImage *)imageWithColor: (UIColor *)color {

? ? CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

? ? UIGraphicsBeginImageContext(rect.size);

? ? CGContextRef context = UIGraphicsGetCurrentContext();

? ? CGContextSetFillColorWithColor(context, [color CGColor]);

? ? CGContextFillRect(context, rect);

? ? UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

? ? UIGraphicsEndImageContext();

? ? return theImage;

}

@end

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市泳梆,隨后出現(xiàn)的幾起案子鳖悠,更是在濱河造成了極大的恐慌,老刑警劉巖优妙,帶你破解...
    沈念sama閱讀 221,635評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件乘综,死亡現(xiàn)場離奇詭異,居然都是意外死亡套硼,警方通過查閱死者的電腦和手機(jī)卡辰,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,543評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來邪意,“玉大人九妈,你說我怎么就攤上這事∥砉恚” “怎么了允蚣?”我有些...
    開封第一講書人閱讀 168,083評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長呆贿。 經(jīng)常有香客問我嚷兔,道長,這世上最難降的妖魔是什么做入? 我笑而不...
    開封第一講書人閱讀 59,640評(píng)論 1 296
  • 正文 為了忘掉前任冒晰,我火速辦了婚禮,結(jié)果婚禮上竟块,老公的妹妹穿的比我還像新娘壶运。我一直安慰自己,他們只是感情好浪秘,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,640評(píng)論 6 397
  • 文/花漫 我一把揭開白布蒋情。 她就那樣靜靜地躺著埠况,像睡著了一般。 火紅的嫁衣襯著肌膚如雪棵癣。 梳的紋絲不亂的頭發(fā)上辕翰,一...
    開封第一講書人閱讀 52,262評(píng)論 1 308
  • 那天,我揣著相機(jī)與錄音狈谊,去河邊找鬼喜命。 笑死,一個(gè)胖子當(dāng)著我的面吹牛河劝,可吹牛的內(nèi)容都是我干的壁榕。 我是一名探鬼主播,決...
    沈念sama閱讀 40,833評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼赎瞎,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼牌里!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起务甥,我...
    開封第一講書人閱讀 39,736評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤牡辽,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后缓呛,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,280評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡杭隙,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,369評(píng)論 3 340
  • 正文 我和宋清朗相戀三年哟绊,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片痰憎。...
    茶點(diǎn)故事閱讀 40,503評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡票髓,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出铣耘,到底是詐尸還是另有隱情洽沟,我是刑警寧澤,帶...
    沈念sama閱讀 36,185評(píng)論 5 350
  • 正文 年R本政府宣布蜗细,位于F島的核電站裆操,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏炉媒。R本人自食惡果不足惜踪区,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,870評(píng)論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望吊骤。 院中可真熱鬧缎岗,春花似錦、人聲如沸白粉。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,340評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至眷细,卻和暖如春拦盹,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背薪鹦。 一陣腳步聲響...
    開封第一講書人閱讀 33,460評(píng)論 1 272
  • 我被黑心中介騙來泰國打工掌敬, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人池磁。 一個(gè)月前我還...
    沈念sama閱讀 48,909評(píng)論 3 376
  • 正文 我出身青樓奔害,卻偏偏與公主長得像,于是被迫代替她去往敵國和親地熄。 傳聞我的和親對(duì)象是個(gè)殘疾皇子华临,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,512評(píng)論 2 359