0. 목적 및 동기
요구되는 디자인이 기본 UIPageControl의 UI를 사용하지 않는다.
그래서 CustomPageControl 이 필요해졌다.
UI control구조에 익숙한 사람이라면 control 들은
subcontrol 들의 조합으로 이루어 졌다는 사실을 예상할 수 있을것이다.
UIPageControl 도 마찬가지로 점들을 이루는 UIImageView 가
subcontrol 로 존재한다.
1. 코드
@interface CustomPageControl : UIPageControl {
}
@end
#import "CustomPageControl.h"
#define kOffImage [UIImage imageNamed:@"offImage.png"]
#define kOnImage [UIImage imageNamed:@"onImage.png"]
@implementation CustomPageControl
- (void)layoutSubviews{
[super layoutSubviews];
UIImage* image = kOffImage;
for(UIImageView* view in self.subviews){
CGRect frame = view.frame;
frame.size = image.size;
view.frame = frame;
view.image = image;
}
}
- (void)setCurrentPage:(int)index{
[super setCurrentPage:index];
for(int i = 0 ; i < [self.subviews count] ; i++){
UIImageView* view = [self.subviews objectAtIndex:i];
view.image = (i == index) ? kOnImage : kOffImage;
}
}
@end
댓글 없음:
댓글 쓰기