Swift实现修改UITableView,UIScrollVie

2020-09-07  本文已影响0人  玉思盈蝶

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
            }
        }
    }

亲测好使哈~~~

参考链接:

https://www.meiwen.com.cn/subject/onwkjqtx.html

https://stackoverflow.com/questions/12005187/ios-changing-uiscrollview-scrollbar-color-to-different-colors/28718210#28718210

上一篇 下一篇

猜你喜欢

热点阅读