ios Changing UIScrollView scrollbar color to different colors

后端 未结 17 2429
我在风中等你
我在风中等你 2020-12-05 07:16

How can we change color of UIScrollview\'s scroll indicator to something like blue, green etc.

I know we can change it to white, black. But other then these colors.

17条回答
  •  青春惊慌失措
    2020-12-05 07:19

    You can change an image of indicator, but you should do this repeadeatly

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        self.chageScrollIndicator()
    }
    
    func chageScrollIndicator (){
        if let indicator = self.collection.subviews.last as? UIImageView {
            let edge = UIEdgeInsets(top: 1.25,
                                    left: 0,
                                    bottom: 1.25,
                                    right: 0)
            indicator.image = UIImage(named: "ScrollIndicator")?.withRenderingMode(.alwaysTemplate).resizableImage(withCapInsets: edge)
            indicator.tintColor = UIConfiguration.textColor
        }
    }
    

    You can use this 2 image as template:

提交回复
热议问题