1、第一种:系统简单的方法indicatorStyle属性:
typedef NS_ENUM(NSInteger, UIScrollViewIndicatorStyle) {
UIScrollViewIndicatorStyleDefault, // black with white border. good against any background
UIScrollViewIndicatorStyleBlack, // black only. smaller. good against a white background
UIScrollViewIndicatorStyleWhite // white only. smaller. good against a black background
};
//分别设置默认值、黑色、白色
tableViews.indicatorStyle = UIScrollViewIndicatorStyleWhite;
2、我们的设计图还不是系统这三种颜色:
func scrollViewDidScroll(_ scrollView: UIScrollView){
if #available(iOS 13, *) {
let verSubView: UIView = scrollView.subviews[(scrollView.subviews.count - 1)]
if let verticalIndicator = verSubView.subviews.first {
verticalIndicator.backgroundColor = UIColor.red
}
let horSubView: UIView = scrollView.subviews[(scrollView.subviews.count - 2)]
if let verticalIndicator = horSubView.subviews.first {
verticalIndicator.backgroundColor = UIColor.green
}
// (scrollView.subviews[(scrollView.subviews.count - 1)].subviews[0]).backgroundColor = UIColor.red //verticalIndicator
// (scrollView.subviews[(scrollView.subviews.count - 2)].subviews[0]).backgroundColor = UIColor.green //horizontalIndicator
} else {
if let verticalIndicator: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 1)] as? UIImageView) {
verticalIndicator.backgroundColor = UIColor.red
}
if let horizontalIndicator: UIImageView = (scrollView.subviews[(scrollView.subviews.count - 2)] as? UIImageView) {
horizontalIndicator.backgroundColor = UIColor.green
}
}
}
亲测好使哈~~~
网友评论