How to change font color of UISegmentedControl

前端 未结 12 1308
广开言路
广开言路 2020-12-04 16:30

I try to change font color from white to black for UISegmentedControl (for iOS 4.*)

UISegmentedControl *button = [[[UISegmentedControl alloc] in         


        
12条回答
  •  伪装坚强ぢ
    2020-12-04 16:54

    If you need to change the text color of the highlighted segment in iOS 7, here is a solution (took me awhile to find, but thanks to this post):

    Objective-C

    [[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]} forState:UIControlStateSelected];
    

    Swift

      let titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]  
      UISegmentedControl.appearance().setTitleTextAttributes(titleTextAttributes, forState: .Selected)
    

提交回复
热议问题