iphone - How can I use a nonstandard color for the UIScrollView indicator? -
the ui gives 3 options uiscrollviewindicatorstyle, want make uiscrollview indicator red, not 1 of standard styles.
can this? if so, how?
yes!! can
both uiscrollview indicator sub view of uiscrollview. so, can access subview of uiscrollview , change property of subview.
1 .add uiscrollviewdelegate
@interface viewcontroller : uiviewcontroller<uiscrollviewdelegate> @end
2. add scrollviewdidscroll in implementation section
-(void)scrollviewdidscroll:(uiscrollview *)scrollview1 { //get refrence of vertical indicator uiimageview *verticalindicator = ((uiimageview *)[scrollview.subviews objectatindex:(scrollview.subviews.count-1)]); //set color vertical indicator [verticalindicator setbackgroundcolor:[uicolor redcolor]]; //get refrence of horizontal indicator uiimageview *horizontalindicator = ((uiimageview *)[scrollview.subviews objectatindex:(scrollview.subviews.count-2)]); //set color horizontal indicator [horizontalindicator setbackgroundcolor:[uicolor bluecolor]]; }
note:- because these indicator update every time when scroll (means reset default). so, put code in scrollviewdidscroll delegate method.
demo available on github - https://github.com/ioshacks/uiscrollviewindicatorcolor
Comments
Post a Comment