在iOS7中UIPageControl的改变

1. 改变:原来PageControl的subview是UIImageView,现在变成了UIView.

2. 解决办法:重画。

3. 代码:(因为我的PageControl通过IB初始化的,所以下面的代码中没有初始化部分。你可以自行初始化

//
//  CustomPageControl.m
//  Sampling
//
//  Created by Megan on 10/18/13.
//  Copyright (c) 2013. All rights reserved.
//

#import "CustomPageControl.h"

@implementation CustomPageControl

- (void)setCurrentPage:(NSInteger)currentPage
{
    [super setCurrentPage:currentPage];
    [self setNeedsDisplay];    
}

- (void)setNumberOfPages:(NSInteger)numberOfPages
{
    [super setNumberOfPages:numberOfPages];
    
     [self setNeedsDisplay];
    
}

- (void)drawRect:(CGRect)iRect
{
    int i;
    CGRect rect;
    UIImage *image;
    
    iRect = self.bounds;
    
    if (self.opaque) {
        [self.backgroundColor set];
        UIRectFill(iRect);
    }
    
    UIImage *_activeImage = [UIImage imageNamed:@"INDICATOR-activated.png"];
    UIImage *_inactiveImage = [UIImage imageNamed:@"INDICATOR-deactivated.png"];
    CGFloat _kSpacing = 5.0f;
    
    if (self.hidesForSinglePage && self.numberOfPages == 1) {
        return;
    }
    
    rect.size.height = _activeImage.size.height;
    rect.size.width = self.numberOfPages * _activeImage.size.width + (self.numberOfPages - 1) * _kSpacing;
    rect.origin.x = floorf((iRect.size.width - rect.size.width) / 2.0);
    rect.origin.y = floorf((iRect.size.height - rect.size.height) / 2.0);
    rect.size.width = _activeImage.size.width;
    
    for (i = 0; i < self.numberOfPages; ++i) {
        image = (i == self.currentPage) ? _activeImage : _inactiveImage;
        [image drawInRect:rect];
        rect.origin.x += _activeImage.size.width + _kSpacing;
    }
}

@end


在iOS7中UIPageControl的改变,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。