暂无描述

FKPageControl.m 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // FKPageControl.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/11/29.
  6. // Copyright © 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKPageControl.h"
  9. #define PER_PAGE_WIDTH 50
  10. #define COMMON_HEIGHT 1.5
  11. @interface FKPageControl ()
  12. @property (nonatomic, strong) UIView *lineBgView;
  13. @property (nonatomic, strong) UIView *actionLine;
  14. @end
  15. @implementation FKPageControl
  16. - (instancetype)initWithFrame:(CGRect)frame{
  17. if (self = [super initWithFrame:frame]) {
  18. self.backgroundColor = [UIColor clearColor];
  19. [self addAllSubviews];
  20. }
  21. return self;
  22. }
  23. - (void)layoutSubviews{
  24. [super layoutSubviews];
  25. self.lineBgView.bounds = CGRectMake(0, 0, PER_PAGE_WIDTH * self.numberOfPages, COMMON_HEIGHT);
  26. self.lineBgView.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
  27. CGFloat bg_x = self.lineBgView.frame.origin.x;
  28. self.actionLine.bounds = CGRectMake(0, 0, PER_PAGE_WIDTH, COMMON_HEIGHT);
  29. self.actionLine.center = CGPointMake(bg_x + (0.5 + self.currentPage) * PER_PAGE_WIDTH , self.lineBgView.center.y);
  30. }
  31. - (void)addAllSubviews{
  32. [self addSubview:self.lineBgView];
  33. [self addSubview:self.actionLine];
  34. }
  35. - (void)setNumberOfPages:(NSUInteger)numberOfPages{
  36. _numberOfPages = numberOfPages;
  37. self.hidden = (_numberOfPages <= 1 ? YES : NO);
  38. [self setNeedsLayout];
  39. [self layoutIfNeeded];
  40. }
  41. - (void)setCurrentPage:(NSUInteger)currentPage{
  42. _currentPage = currentPage;
  43. [self setNeedsLayout];
  44. [self layoutIfNeeded];
  45. }
  46. - (void)setPageIndicatorTintColor:(UIColor *)pageIndicatorTintColor{
  47. self.lineBgView.backgroundColor = pageIndicatorTintColor;
  48. }
  49. - (void)setCurrentPageIndicatorTintColor:(UIColor *)currentPageIndicatorTintColor{
  50. self.actionLine.backgroundColor = currentPageIndicatorTintColor;
  51. }
  52. - (UIView *)lineBgView{
  53. if (_lineBgView == nil) {
  54. _lineBgView = [[UIView alloc]init];
  55. _lineBgView.userInteractionEnabled = NO;
  56. _lineBgView.backgroundColor = [UIColorFromRGB(0xffffff) colorWithAlphaComponent:0.5];
  57. }
  58. return _lineBgView;
  59. }
  60. - (UIView *)actionLine{
  61. if (_actionLine == nil) {
  62. _actionLine = [[UIView alloc]init];
  63. _actionLine.userInteractionEnabled = NO;
  64. _actionLine.backgroundColor = [UIColor whiteColor];
  65. }
  66. return _actionLine;
  67. }
  68. @end