具有圆形背景的自定义分段控件

时间:2019-05-01 07:14:44

标签: swift customization uisegmentedcontrol

希望有人可以帮助我... 我已经创建了一个UISegmented控件,并开始将其更改为我的应用程序设计-请参见下面的屏幕截图。

如果你们可以看到分段选项的背景,那么您将看到我的问题。我设法通过以下功能更改了颜色,文本和其他一些小东西:

What I have so far

extension UISegmentedControl {

func defaultConfiguration(font: UIFont = UIFont(name: "Montserrat-Regular", size: 13)!, textColor: UIColor = UIColor.white, backgroundColor: UIColor = UIColor.clear) {
    let defaultAttributes: [NSAttributedString.Key : Any] = [
        NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): font,
        NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): textColor,
        NSAttributedString.Key(rawValue: NSAttributedString.Key.backgroundColor.rawValue): backgroundColor
    ]
    setTitleTextAttributes(defaultAttributes, for: .normal)
}

func selectedConfiguration(font: UIFont = UIFont(name: "Montserrat-Regular", size: 13)!, textColor: UIColor = UIColor.rgb(red: 52, green: 0, blue: 177), backgroundColor: UIColor = UIColor.white) {
    let selectedAttributes: [NSAttributedString.Key : Any] = [
        NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue): font,
        NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): textColor,
        NSAttributedString.Key(rawValue: NSAttributedString.Key.backgroundColor.rawValue): backgroundColor
    ]
    setTitleTextAttributes(selectedAttributes, for: .selected)
    }
}

我希望背景变得更大且更圆整……有什么想法我所缺少的吗?用户单击时,应该看到以下内容

WHAT I NEED:

0 个答案:

没有答案