UITableView always displays the scroll bar (ScrollBar Indicators), scroll bar Width (Width), and scroll bar Co

Source: Internet
Author: User

In IOS, the user-defined interface for the ScrollBar Indicators of UIScrollView has always been rare. In addition to customizing simple styles (UIScrollViewIndicatorStyle) and enabling or not, the Width and color of the scroll bar and ScrollBar Indicators are always displayed, they are not easy to set. Although not convenient, it can still be implemented. Through one day's effort and constant google and overflow, we finally found several perfect solutions.

This article prohibits reprinting on any website and severely condemn the worms.
This article was first published in, blog garden. Please search: blog garden-Find yourself and view the original article
This article first address: UITableView always display scroll bar (ScrollBar Indicators), scroll bar Width (Width), scroll bar Color (Color)-http://www.cnblogs.com/xunziji/p/3248850.html

The following is a step-by-step analysis:

1. You can set the scroll bar (ScrollBar Indicators) for those controls)

Because UIScrollView is the parent class of UITableView and UITextView, you can set Controll: UIScrollView, UITableView, and UITextView.

 

2. The-(void) flashScrollIndicators method of UIScrollView

This method displays the scroll bar (ScrollBar Indicators) of UIScrollView by calling the object-c method ). But the tragedy is that the scroll bar Indicators will only display about 1.5 seconds, and will be automatically hidden. However, this method still has some application scenarios. For example, if you think that a 2-second scroll bar will be displayed on the right side of the UIScrollView Load time, this method just fits you: [tableProdList reloadData]; if (tableProdList. contentSize. height> tableProdList. frame. size. height) {tableProdList flashScrollIndicators];}

 

3. What is a scroll bar Indicators, how it is displayed and hidden?

The scroll bar of UIScrollView (ScrollBar Indicators) is the darkgray bar on the right by default. When you scroll down a UIScrollView, the scroll bar will be displayed, and the display and hide will fade in and out. This is, you may be able to guess what it is: UIImageView. the scroll bar is a UIImageView, And that scroll bar is just an image. The disappearance and hiding of the scroll bar fade-in and fade-out are the void setAlpha method of the UIImageView.

 

This article prohibits reprinting on any website and severely condemn the worms.
This article was first published in, blog garden. Please search: blog garden-Find yourself and view the original article
This article first address: UITableView always display scroll bar (ScrollBar Indicators), scroll bar Width (Width), scroll bar Color (Color)-http://www.cnblogs.com/xunziji/p/3248850.html4. the first way to keep the scroll bar displayed (if you want to solve the problem quickly, please refer to the last more perfect and faster solution)

When finding a solution on StackOverFlow, the answer to many questions points to this Code:

 noDisableVerticalScrollTag 836913 noDisableHorizontalScrollTag 836914- () setAlpha:( (self.superview.tag == (alpha ==  && self.autoresizingMask == (self.frame.size.width <  && self.frame.size.height >*sc = (UIScrollView* (sc.frame.size.height < (self.superview.tag == (alpha ==  && self.autoresizingMask == (self.frame.size.height <  && self.frame.size.height <*sc = (UIScrollView* (sc.frame.size.width <

 

When I saw this code, I thought: I want to set UIScrollView, but you set UIImageView; I want to set ScrollBar Indicators, but you set alpha. In addition, I rely on the original article to describe how to use this code, and I have not even explained it. As a result, I had taken a lot of detours. I don't know, but this code can be perfectly solved.

 

First, explain the code.Otherwise, I will not be scolded for being seen by other hard-pressed, staying up late, and working overtime programs? :

 

A. This is a Category.Objective-C provides a very flexible Class extension mechanism-Category ). A category is used to add a method (Methods) to an existing class ). You only need to know the public interface of this class, and do not need to know the source code of the class. You must note that the category cannot add Instance Variables for an existing class ).Therefore, this code inherits the UIImageView class and overwrites the setAlpha method. For how to add this code to the project, see:

ProdDetailsTable. tag =;

 

C. To bind UIScrollView data, that is, after loading: flashScrollIndicators

 

 

 

This article prohibits reprinting on any website and severely condemn the worms.
This article was first published in, blog garden. Please search: blog garden-Find yourself and view the original article
This article first address: UITableView always display scroll bar (ScrollBar Indicators), scroll bar Width (Width), scroll bar Color (Color)-http://www.cnblogs.com/xunziji/p/3248850.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.