Customizing the colors of a UISegmentedControl

后端 未结 12 1866
萌比男神i
萌比男神i 2020-12-08 07:26

Does anybody know of a way to customize the appearance of the string based UISegmentedControl? I am trying to set the background color of the cell and the text color differe

12条回答
  •  渐次进展
    2020-12-08 08:21

    Font Color swift 3 and swift 4 if you want to change

    For Unselected item

     segcntrl.setTitleTextAttributes(titleTextAttributes, for: .normal)
    

    For Selected item

      segcntrl.setTitleTextAttributes(titleTextAttributes, for: .selected)
    
    
    
    //MARK:- Segment color change
        self.segc.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: 
    UIColor.white], for: UIControlState.selected)
        self.segc.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: 
    UIColor.white], for: UIControlState.normal)
    

提交回复
热议问题