iOS 给UISlider加刻度(超简单)
2019-12-16 本文已影响0人
梦醒了i77
Simulator Screen Shot - iPhone 11 Pro Max - 2019-12-16 at 14.52.33.png
DispatchQueue.main.async {
let view = UIView()
view.frame = viewSlider.frame
let layer = CALayer()
layer.frame = CGRect(x: 0, y: viewSlider.frame.size.height * 0.26, width: 2, height: viewSlider.frame.size.height * 0.25)
layer.backgroundColor = color.cgColor
let layerReplicator = CAReplicatorLayer()
layerReplicator.frame = viewSlider.bounds
view.layer.addSublayer(layerReplicator)
layerReplicator.addSublayer(layer)
layerReplicator.instanceCount = Int(viewSlider.maximumValue) + 1
let width = viewSlider.frame.size.width - 2
let space = width / CGFloat(viewSlider.maximumValue)
layerReplicator.instanceTransform = CATransform3DMakeTranslation(space, 0, 0);
viewSlider.superview!.insertSubview(view, at: 0)
}
- 不是直接给UISlider添加CALayer是防止复制图层盖住thumb