美文网首页
Swift实现修改UITableView,UIScrollVie

Swift实现修改UITableView,UIScrollVie

作者: 玉思盈蝶 | 来源:发表于2020-09-07 16:47 被阅读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

    相关文章

      网友评论

          本文标题:Swift实现修改UITableView,UIScrollVie

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