12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- //
- // FKPageControl.m
- // FirstLink
- //
- // Created by jack on 15/11/29.
- // Copyright © 2015年 FirstLink. All rights reserved.
- //
- #import "FKPageControl.h"
- #define PER_PAGE_WIDTH 50
- #define COMMON_HEIGHT 1.5
- @interface FKPageControl ()
- @property (nonatomic, strong) UIView *lineBgView;
- @property (nonatomic, strong) UIView *actionLine;
- @end
- @implementation FKPageControl
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- self.backgroundColor = [UIColor clearColor];
- [self addAllSubviews];
- }
- return self;
- }
- - (void)layoutSubviews{
- [super layoutSubviews];
-
- self.lineBgView.bounds = CGRectMake(0, 0, PER_PAGE_WIDTH * self.numberOfPages, COMMON_HEIGHT);
- self.lineBgView.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
-
- CGFloat bg_x = self.lineBgView.frame.origin.x;
-
- self.actionLine.bounds = CGRectMake(0, 0, PER_PAGE_WIDTH, COMMON_HEIGHT);
- self.actionLine.center = CGPointMake(bg_x + (0.5 + self.currentPage) * PER_PAGE_WIDTH , self.lineBgView.center.y);
- }
- - (void)addAllSubviews{
- [self addSubview:self.lineBgView];
- [self addSubview:self.actionLine];
- }
- - (void)setNumberOfPages:(NSUInteger)numberOfPages{
- _numberOfPages = numberOfPages;
- self.hidden = (_numberOfPages <= 1 ? YES : NO);
-
- [self setNeedsLayout];
- [self layoutIfNeeded];
- }
- - (void)setCurrentPage:(NSUInteger)currentPage{
- _currentPage = currentPage;
-
- [self setNeedsLayout];
- [self layoutIfNeeded];
- }
- - (void)setPageIndicatorTintColor:(UIColor *)pageIndicatorTintColor{
- self.lineBgView.backgroundColor = pageIndicatorTintColor;
- }
- - (void)setCurrentPageIndicatorTintColor:(UIColor *)currentPageIndicatorTintColor{
- self.actionLine.backgroundColor = currentPageIndicatorTintColor;
- }
- - (UIView *)lineBgView{
- if (_lineBgView == nil) {
- _lineBgView = [[UIView alloc]init];
- _lineBgView.userInteractionEnabled = NO;
- _lineBgView.backgroundColor = [UIColorFromRGB(0xffffff) colorWithAlphaComponent:0.5];
- }
- return _lineBgView;
- }
- - (UIView *)actionLine{
- if (_actionLine == nil) {
- _actionLine = [[UIView alloc]init];
- _actionLine.userInteractionEnabled = NO;
- _actionLine.backgroundColor = [UIColor whiteColor];
- }
- return _actionLine;
- }
- @end
|