作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
最佳答案
代码
extension UIView {
///Add border color with corners
func addBorderWithColor(color: UIColor, roundingCorners: UIRectCorner) {
self.layer.borderWidth = 1
self.layer.borderColor = color.CGColor
self.addRoundingCorners(roundingCorners)
}
///Use corner radius depending on UIRectCorner
private func addRoundingCorners(roundingCorners: UIRectCorner) {
let path = UIBezierPath(roundedRect:self.bounds, byRoundingCorners:roundingCorners, cornerRadii: CGSizeMake(4, 4))
let maskLayer = CAShapeLayer()
maskLayer.path = path.CGPath
self.layer.mask = maskLayer
}
}
let segmentedControl = UISegmentedControl(items: ["Red", "Green", "Blue"])
segmentedControl.subviews[0].addBorderWithColor(UIColor.blueColor(), roundingCorners: [.TopRight, .BottomRight])
segmentedControl.subviews[1].addBorderWithColor(UIColor.greenColor(), roundingCorners: [])
segmentedControl.subviews[2].addBorderWithColor(UIColor.redColor(), roundingCorners: [.TopLeft, .BottomLeft])
segmentedControl.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blackColor()], forState: UIControlState.Normal)
Playground
代码
let segmentedControl = UISegmentedControl(items: ["Red", "Green", "Blue"])
//Change Text Attributes (Changing textColor to black)
//**Be sure to manage all the UIControlState for these attributes if you need to customize this for other states
segmentedControl.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blackColor()], forState: UIControlState.Normal)
//Change tintColor to clear, in order to set border invisible
segmentedControl.tintColor = UIColor.clearColor()
Playground
答案是NO
您无法移除 UISegmentedControl
您可以通过使用 UIButton
创建自定义控件来实现您正在寻找的内容。
在UISegmentedControl
状态下,可以去掉UISegmentedControl
中item之间的分隔符,也可以改变tintColor(borderColor)
关于ios - 如何从 UISegmentController 中删除边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34334967/
我是一名优秀的程序员,十分优秀!