如何更改 UIText 视图垂直滚动条指示器颜色?

How to change the UIText view vertical scrollbar indicator color?

是否可以更改 UITextView 垂直滚动条指示器的颜色?根据要求,我正在使用文本视图并希望更改滚动条指示器的颜色。

textView.isScrollEnabled = true
textView.showVerticalScrollIndicator = true

提前致谢!

使用以下代码更新 UIScrollView

的指示器颜色
func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let verticalIndicator: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 1)] as! UIImageView)

    verticalIndicator.backgroundColor = UIColor(red: 211/255.0, green: 138/255.0, blue: 252/255.0, alpha: 1).

}

您必须从 UITextView 的属性更改黑白颜色

1 .添加 UIScrollViewDelegate

@interface ViewController : UIViewController<UIScrollViewDelegate>
@end

2。在实现部分添加 scrollViewDidScroll

如果你必须改变新的颜色,那么你必须使用

    func scrollViewDidScroll(scrollView: UIScrollView){
        let verticalIndicator: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 1)] as! UIImageView)
        verticalIndicator.backgroundColor = UIColor.greenColor()

        let horizontalIndicator: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 2)] as! UIImageView)
        horizontalIndicator.backgroundColor = UIColor.blueColor()
   }