Swift3 如何在Swift 3.0中使用HMSegmentedControl设置选定的段背景色

Swift3 如何在Swift 3.0中使用HMSegmentedControl设置选定的段背景色,swift3,uisegmentedcontrol,Swift3,Uisegmentedcontrol,选择索引时,如何使用HMSegmentedControl实现此样式。如果可能,请帮助我如何在swift 3.0中实现此样式 这是我的密码: func setupSegementCategory(){ segmentCategory.sectionTitles = ["home","about","contract","home","about","contract"] segmentCategory.backgroundColor = #colorLiter

选择索引时,如何使用HMSegmentedControl实现此样式。如果可能,请帮助我如何在swift 3.0中实现此样式

这是我的密码:

 func setupSegementCategory(){
        segmentCategory.sectionTitles =  ["home","about","contract","home","about","contract"]
        segmentCategory.backgroundColor = #colorLiteral(red: 0.7683569193, green: 0.9300123453, blue: 0.9995251894, alpha: 1)
        segmentCategory.translatesAutoresizingMaskIntoConstraints = false
        segmentCategory.selectionIndicatorLocation=HMSegmentedControlSelectionIndicatorLocation.down
        segmentCategory.isVerticalDividerEnabled=false
        segmentCategory.selectedSegmentIndex=0
        segmentCategory.selectionIndicatorColor = UIColor.white
        segmentCategory.segmentWidthStyle = HMSegmentedControlSegmentWidthStyle.dynamic
        segmentCategory.titleTextAttributes = [
            NSForegroundColorAttributeName : #colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1),
            NSFontAttributeName : UIFont.systemFont(ofSize: 17)
        ]
        segmentCategory.backgroundColor=Constant.GlobalConstants.kColor_blue
        segmentCategory.selectedTitleTextAttributes = [
            NSFontAttributeName : UIFont.systemFont(ofSize: 17),
            NSForegroundColorAttributeName :UIColor(red:0.74, green:0.70, blue:1.00, alpha:1.0)
        ]

        segmentCategory.addTarget(self, action:#selector(segmentedControlValueChanged(sender:)), for: .valueChanged)


    }
    func segmentedControlValueChanged(sender: UISegmentedControl) {
        let sortedViews = sender.subviews.sorted( by: { $0.frame.origin.x < $1.frame.origin.x } )

        for (index, view) in sortedViews.enumerated() {
            if index == sender.selectedSegmentIndex {
                view.tintColor = UIColor.red
            } else {
                view.tintColor = UIColor.lightGray
            }
        }
    }
func setupSegementCategory(){
segmentCategory.sectionTitles=[“主页”、“关于”、“合同”、“主页”、“关于”、“合同”]
segmentCategory.backgroundColor=#colorLiteral(红色:0.7683569193,绿色:0.9300123453,蓝色:0.9995251894,alpha:1)
segmentCategory.TranslatesAutoResizezingMaskintoConstraints=false
segmentCategory.selectionIndicatorLocation=HMSegmentedControlSelectionIndicatorLocation.down
segmentCategory.isVerticalDividerEnabled=false
segmentCategory.selectedSegmentIndex=0
segmentCategory.SelectionIndicator颜色=UIColor.white
segmentCategory.segmentWidthStyle=HMSegmentedControlSegmentWidthStyle.dynamic
segmentCategory.titleTextAttributes=[
NSForegroundColorAttributeName:#colorLiteral(红色:0.2549019754,绿色:0.2745098174,蓝色:0.3019607961,alpha:1),
NSFontAttributeName:UIFont.systemFont(大小:17)
]
segmentCategory.backgroundColor=Constant.GlobalConstants.kColor\u blue
segmentCategory.selectedTitleTextAttributes=[
NSFontAttributeName:UIFont.systemFont(大小:17),
NSForegroundColorAttributeName:UIColor(红色:0.74,绿色:0.70,蓝色:1.00,alpha:1.0)
]
segmentCategory.addTarget(self,action:#选择器(segmentedControlValueChanged(sender:)),for:.valueChanged)
}
func segmentedControlValueChanged(发送方:UISegmentedControl){
让sortedViews=sender.subviews.sorted(按:{$0.frame.origin.x<$1.frame.origin.x})
用于SortedView.enumerated()中的(索引、视图){
如果index==sender.selectedSegmentIndex{
view.tintColor=UIColor.red
}否则{
view.tintColor=UIColor.lightGray
}
}
}

目前无法在HMSegmentedControl中获得这种样式