UITableView scroll bar

Source: Internet
Author: User

UITableView always displays scrollbars (ScrollBar indicators), scroll bar width (width), scroll bar color (color)

Reprinted from Http://www.cnblogs.com/xunziji/p/3248850.html

In IOS, the custom settings interface for the Uiscrollview scroll bar (ScrollBar indicators) has been minimal. In addition to being able to customize the simple style (Uiscrollviewindicatorstyle) and whether it is enabled, it is not easy to set the width, color, etc. of the scroll bar, custom scroll bar (ScrollBar indicators) that are always displayed. Although not very convenient, but still can be achieved. Through a day of efforts, and constantly Google and overflow, finally found a few more perfect solutions.

The following first step analysis:

1. Those controls can be set to scroll bar (ScrollBar indicators)

Because Uiscrollview is the parent class of UITableView and Uitextview, you can set the Controll:uiscrollview, UITableView, Uitextview.

2. Uiscrollview-(void) Flashscrollindicators method

The method is to call the Object-c method to display the Uiscrollview scroll bar (ScrollBar indicators). But the tragedy is that the scroll bar (ScrollBar indicators) will only show about 1.5 seconds or so, and it will be automatically hidden. However, the method still has a certain application scenario, such as you think as long as the Uiscrollview Load time, the right side of the display 2 seconds scroll bar can play a hint, that this method just satisfies you: [Tableprodlist reloaddata]; if (TableProdList.contentSize.height > TableProdList.frame.size.height) {tableprodlist flashscrollindicators]; }

3. What the scroll bar (ScrollBar indicators) is, how it is displayed and hidden away

Uiscrollview scroll bar (ScrollBar indicators), is the default right side of the Darkgray bar, when you scroll a uiscrollview time, the scroll bar will be displayed, and the display and hide are fade in and fade out. This is, you may be able to guess what it is: Uiimageview. The scrollbar is a uiimageview, and that scroll bar is just a picture. The Uiimageview-(void) Setalpha method is set for the vanishing and hidden fade of the scroll bar.

4. The first way to keep the scrollbar displayed (if you want to solve the problem quickly, just look at the last more perfect, faster solution)

When looking for a solution on StackOverflow, the answers to many questions point to this code:

#define NODISABLEVERTICALSCROLLTAG 836913#define NODISABLEHORIZONTALSCROLLTAG 836914@implementationUiimageview (Forscrollview)-(void) Setalpha: (Float) Alpha {if (Self.superview.tag = =Nodisableverticalscrolltag) {if (alpha = =0 && Self.autoresizingmask = =Uiviewautoresizingflexibleleftmargin) {if (Self.frame.size.width <&& self.frame.size.height >Self.frame.size.width) {Uiscrollview *SC = (uiscrollview*) Self.superview;if (Sc.frame.size.height <Sc.contentSize.height) {returnif (Self.superview.tag == Nodisablehorizontalscrolltag) {if (alpha = = 0 & & self.autoresizingmask == Uiviewautoresizingflexibletopmargin) {if (Self.frame.size.height < 10 && self.frame.size.height < Self.frame.size.width) {Uiscrollview *SC = (uiscrollview*if (sc.frame.size.width < Sc.contentSize.width) { @end             

Just see this code of time, I think: this what the hair code, I want to set Uiscrollview, you but set Uiimageview; I want to set ScrollBar indicators, but you set alpha. Moreover this code how to use, I, the original text to put out this piece of code, even explain not. As a result, I have gone a lot of detours, do not know, this code can be a perfect solution.

first of all to explain this code , or other bitter force, stay up late, overtime program Ape See, will not use, I will not be scolded? :

A. This is a category Objective-c provides a very flexible class extension mechanism-categories. The category is used to add a method (Methods) to an already existing class. You just need to know the public interface of this class, and you don't have to know the source code of the class. It is important to note that a category cannot add an instance variable (Instance Variables) to a class that already exists. so this code inherits the Uiimageview class and overrides the Setalpha method. For information on how to add this code to your project, see:

B. The method uses tag to determine whether the scroll bar needs to be displayed all the time because the method overrides the Setalpha, so all the Uiimageview will request this code in the load, and this world cannot be handled by each, so, by the Controller's Tag to distinguish, is also a good choice. Of course, here is the comparison of the tag is equal, you can also compare the tag is greater than a certain value and so on.

C. Through the If comparison of some columns, determine whether the uiscrollview is a horizontal or vertical scrollbar, whether the Uiimageview is the body content area that you want to hide and uiscrollview overflow to determine if you want to hide, that is, whether you want to set: [Super SetA LPHA:0];

D. If you execute [Super setalpha:0], then hide and return to continue showing

How to use:

A. Follow the image to create a Category and Copy the code in

B. Within the Viewdidload:

 836913;

C. After Uiscrollview data binding, that is, after the load is complete: flashscrollindicators

 [Proddetailstable reloaddata];[ Proddetailstable Flashscrollindicators];

UITableView scroll bar

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.