Summary of iOS Uipagecontrol point color settings

Source: Internet
Author: User
Tags uikit

iOS Pagecontrol control does not have a point color settings, the beginning of their own do not believe, a color property modification, Apple will not so pit it, do a lot of things you will slowly find that Apple is so resistant, a lot of functions to improve themselves.

Originally found some information on the internet is to Pagecontrol point as a uiimage, I use the xcode5.2 debugging found that Pagecontrol child control is not Uiimageview, the point is a uiviwe, by modifying the View Layer control shape. When you know this, you have the idea.

Ideas:

1, write an inheritance Uipagecontrol class

2, rewrite the setcurrentpage method of Uipagecontrol

3, modify the color of the current point

Code

#import <UIKit/UIKit.h>

@interface Commonpagecontrol:uipagecontrol
{
UIImage *activeimage;
UIImage *inactiveimage;
}
@end #import "CommonPageControl.h"

@implementation Commonpagecontrol

-(ID) initWithFrame: (CGRect) frame
{
self = [super Initwithframe:frame];
if (self) {
Initialization code
}
return self;
}

-(void) updatedots{

for (int i=0;i<[self.subviews count];i++) {

if ([(UIView *) [Self.subviews objectatindex:i] Iskindofclass:[uiview class]) {//current Pagecontrol control dot is a view
UIView *dot=[self.subviews OBJECTATINDEX:I];
if (i==self.currentpage) {
Dot.backgroundcolor=[uicolor Whitecolor];

}
else{
Dot.backgroundcolor = [Uicolor colorwithred:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.1];


}
}

}

}

overriding base class methods
-(void) Setcurrentpage: (Nsinteger) currentpage{

[Super Setcurrentpage:currentpage];
[Self updatedots];

}
@end call: CGRect rect;
rect.origin.x = myscrollview.frame.origin.x;
RECT.ORIGIN.Y = self.frame.size.height-20;
Rect.size.width = MyScrollView.frame.size.width;
Rect.size.height = 20; Mypagecontrol = [[Commonpagecontrol alloc] initwithframe:rect];
Mypagecontrol.userinteractionenabled=no;

Related Article

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.