iOS/코드조각

[iOS, Swift] SegmentController 색상 변경

검은참깨두유vm 2022. 10. 8. 10:07
반응형

iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다.

 

let oneColor = UIColor(red: 255/255, green: 216/255, blue: 0, alpha: 1)
let twoColor = UIColor(red: 88/255, green: 112/255, blue: 88/255, alpha: 1)

segmentedControl.backgroundColor = oneColor
segmentedControl.selectedSegmentTintColor = twoColor 
segmentedControl.setTitleTextAttributes([.foregroundColor: twoColor as Any], for: .normal)
segmentedControl.setTitleTextAttributes([.foregroundColor: oneColor as Any], for: .selected)

 

반응형