How to change the colors of a segment in a UISegmentedControl in iOS 13?

前端 未结 14 865
醉话见心
醉话见心 2020-11-30 18:13

A UISegmentedControl has a new appearance in iOS 13 and existing code to alter the colors of the segmented control no longer work as they did.

Prior to

14条回答
  •  佛祖请我去吃肉
    2020-11-30 18:37

    if (@available(iOS 13.0, *)) {
    
        [self.segmentedControl setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont systemFontOfSize:13]} forState:UIControlStateSelected];
        [self.segmentedControl setSelectedSegmentTintColor:[UIColor blueColor]];
    
    } else {
    
    [self.segmentedControl setTintColor:[UIColor blueColor]];}
    

提交回复
热议问题