mardi 4 août 2015

uipageview controller cannot update dot images using iOS 8?

I have created custom class with subclasss of UIPageControl

customClass.h

@interface customclass : UIPageControl
{
    UIImage* activeImage;
    UIImage* inactiveImage;
}
@property(nonatomic, retain) UIImage* activeImage;
@property(nonatomic, retain) UIImage* inactiveImage;
@property (weak, nonatomic) IBOutlet UIPageControl *pageController;

@end

customclass.m file

@implementation customclass
@synthesize activeImage,inactiveImage;
-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if(self)
    {
       activeImage = [UIImage imageNamed:@"dots.png"];
       inactiveImage = [UIImage imageNamed:@"off.png"];


    }
    return self;
}
-(id)init
{
    self = [super init];
    if(self)
    {
        activeImage = [UIImage imageNamed:@"dots.png"];
        inactiveImage = [UIImage imageNamed:@"off.png"];

    }
    return self;
}

-(void)updateDots
{
        for (int i = 0; i < [self.subviews count]; i++)
        {
            UIImageView * dot = [self imageViewForSubview:  [self.subviews objectAtIndex: i]];
            if (i == self.currentPage) dot.image = activeImage;
            else dot.image = inactiveImage;
        }

}

- (UIImageView *) imageViewForSubview: (UIView *) view
{
    UIImageView * dot = nil;
    if ([view isKindOfClass: [UIView class]])
    {
        for (UIView* subview in view.subviews)
        {
            if ([subview isKindOfClass:[UIImageView class]])
            {
                dot = (UIImageView *)subview;
                break;
            }
        }
        if (dot == nil)
        {
            dot = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 17,17)];
            [view addSubview:dot];
        }
    }
    else
    {
        dot = (UIImageView *) view;
    }

    return dot;
}


-(void)setCurrentPage:(NSInteger)page
{
    [super setCurrentPage:page];
    [self updateDots];
}

the following line never executed.I am using iOS 8.3

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

here never get into that loop..

i dont know whats going on here..

i am following this Link

i have called at my uipageviewcontroller like this...

pageControl=[[customclass alloc]init];
    [pageControl setCurrentPage:0];



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire