Swift:UISlider 轨道的一侧没有圆角 [英] Swift: UISlider one side of track not rounded
本文介绍了Swift:UISlider 轨道的一侧没有圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义 UISlider,但滑块的一侧不是圆形的
I have a custom UISlider, but there is a side of the slider which is not rounded
这里是我的自定义视图:
Here my custom view:
class PrimarySliderView: UISlider {
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setup()
}
override func trackRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(origin: bounds.origin, size: CGSize(width: bounds.width, height: 6))
}
func setup() {
tintColor = .cornFlowerBlue
}
如何将右侧也倒圆?
编辑
因为我的应用程序是RTL,所以滑块被剪掉了,当我改成LTR这个显示正确但不是RTL,如何解决这个问题?
The slider is cutted because my application is RTL, when I change to LTR this display correctly but not in RTL, how to resolve this problem?
在我的 AppDelegate 中,我强制 RTL:
In My AppDelegate I force RTL:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UIView.appearance().semanticContentAttribute = .forceRightToLeft
return true
}
推荐答案
或者你需要为最小和最大轨道添加圆角图像或者您可以使用颜色创建圆形视图
Either you need to add rounded image for minimum and maximum track or you can create rounded view using colors
其他解决方法是
override func layoutSubviews() {
super.layoutSubviews()
self.layer.sublayers![1].cornerRadius = 10
}
这篇关于Swift:UISlider 轨道的一侧没有圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文