你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> GrayPageControl 在 IOS7 崩潰解決方案

GrayPageControl 在 IOS7 崩潰解決方案

編輯:關於IOS

網上開源的GrayPageControl 在ios7下會崩潰,因為ios7修改了UIPageControl內部的實現

stackoverflow 中改出解決方案 注意修改紅體字部分

#import "GrayPageControl.h"

@implementation GrayPageControl

-(id) initWithCoder:(NSCoder *)aDecoder

{

self = [super initWithCoder:aDecoder];

activeImage = [UIImage imageNamed:@"inactive_page_image"];

inactiveImage = [UIImage imageNamed:@"active_page_image"];

[self setCurrentPage:1];

return self;

}

- (id)initWithFrame:(CGRect)aFrame {

if (self = [super initWithFrame:aFrame]) {

activeImage = [UIImage imageNamed:@"inactive_page_image"];

inactiveImage = [UIImage imageNamed:@"active_page_image"];

[self setCurrentPage:1];

}

return self;

}

-(void) updateDots

{

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

{

UIView* dotView = [self.subviews objectAtIndex:i];

UIImageView* dot = nil;

for (UIView* subview in dotView.subviews)

{

if ([subview isKindOfClass:[UIImageView class]])

{

dot = (UIImageView*)subview;

break;

}

}

if (dot == nil)

{

dot = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, dotView.frame.size.width, dotView.frame.size.height)];

[dotView addSubview:dot];

}

if (i == self.currentPage)

{

if(activeImage)

dot.image = activeImage;

}

else

{

if (inactiveImage)

dot.image = inactiveImage;

}

}

}

-(void) setCurrentPage:(NSInteger)page

{

[super setCurrentPage:page];

[self updateDots];

}

具體請參考 http://stackoverflow.com/questions/18975544/uipagecontrol-is-not-with-uiimageview-in-ios7

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved