美文网首页
iOS 给UISlider加刻度(超简单)

iOS 给UISlider加刻度(超简单)

作者: 梦醒了i77 | 来源:发表于2019-12-16 14:54 被阅读0次
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

相关文章

网友评论

      本文标题:iOS 给UISlider加刻度(超简单)

      本文链接:https://www.haomeiwen.com/subject/bmcdnctx.html