Change width and colour of scroll bar in UITableView, iphone

前端 未结 8 1518
时光说笑
时光说笑 2020-11-30 06:53

I could only find if one wants to display scroll bar or not using

tableView.showsVerticalScrollIndicator = YES/NO;

but how can I customize

相关标签:
8条回答
  • 2020-11-30 07:06

    I did'n find any other way but this:

    UITableView *v;
    [v setIndicatorStyle:<#(UIScrollViewIndicatorStyle)#>];
    

    There is only 3 available styles. If only you will find the way to implement your own UIScrollViewIndicatorStyle, but I can't even imagine HOW to do this: they are implemented deep in UIKit framework (declared in UIScrollView.h), and you can only set a flag, witch will used by UIScrollView to know, what style to use. So, I can't see any other way: you will need somehow to implement new style and flag there. Is it possible at all?

    0 讨论(0)
  • 2020-11-30 07:08

    You can hide the original scroll bar and scroll using your custom scroll bar.

    – (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated 
    

    can be used to scroll content, just add your custom bar to the table.

    0 讨论(0)
  • 2020-11-30 07:08

    For Swift 3

    collectionView.indicatorStyle = UIScrollViewIndicatorStyle.white

    0 讨论(0)
  • 2020-11-30 07:08

    change indicator color with 3 default color style.

    TextField.indicatorStyle=UIScrollViewIndicatorStyleWhite;

    0 讨论(0)
  • 2020-11-30 07:10

    You can change the scroll indicator color using:

    tableView.indicatorStyle=UIScrollViewIndicatorStyleWhite;
    

    Hope this helps.

    0 讨论(0)
  • 2020-11-30 07:12

    Swift-3,4

    If you are not able to override method "scrollViewDidScroll" (may be you are using this for some other functionality, or paging), Try this !!

    func setScrollIndicatorColor(color: UIColor) {
            for view in self.tableView.subviews {
                if view.isKind(of: UIImageView.self),
                    let imageView = view as? UIImageView,
                    let _ = imageView.image  {
                    imageView.image = nil
                    view.backgroundColor = color
                }
            }
    
            self.tableView.flashScrollIndicators()
        }
    

    in viewDidAppear() you can call this method.

    0 讨论(0)
提交回复
热议问题