LibraryNavigationPanel.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // LibraryNavigationPanel.m
  3. //
  4. //
  5. // Created by Alexi on 3/11/14.
  6. // Copyright (c) 2014 Harman. All rights reserved.
  7. //
  8. #if kSupportLibraryPage
  9. #import "LibraryNavigationPanel.h"
  10. @implementation LibraryNavigationPanel
  11. - (instancetype)initWith:(NSArray *)titles
  12. {
  13. if (self = [super initWithFrame:CGRectZero])
  14. {
  15. _titles = [NSMutableArray arrayWithArray:titles];
  16. [self addOwnViews];
  17. [self configOwnViews];
  18. [self select:0];
  19. }
  20. return self;
  21. }
  22. - (void)addOwnViews
  23. {
  24. _title = [[UILabel alloc] init];
  25. _title.textAlignment = NSTextAlignmentCenter;
  26. _title.textColor = kWhiteColor;
  27. _title.font = kAppSmallTextFont;
  28. [self addSubview:_title];
  29. _pageView = [[UIPageControl alloc] init];
  30. _pageView.numberOfPages = _titles.count;
  31. _pageView.pageIndicatorTintColor = kGrayColor;
  32. _pageView.currentPageIndicatorTintColor = kWhiteColor;
  33. [_pageView addTarget:self action:@selector(onChangePage:) forControlEvents:UIControlEventValueChanged];
  34. [self addSubview:_pageView];
  35. }
  36. - (void)onChangePage:(UIPageControl *)pageCtrl
  37. {
  38. if ([_delegate respondsToSelector:@selector(onLibraryNavigationPanel:navigateTo:)])
  39. {
  40. [_delegate onLibraryNavigationPanel:self navigateTo:pageCtrl.currentPage];
  41. }
  42. }
  43. #define kTitleHeight 30
  44. - (void)relayoutFrameOfSubViews
  45. {
  46. CGRect rect = self.bounds;
  47. CGRect titleRect = rect;
  48. titleRect.size.height = kTitleHeight;
  49. _title.frame = titleRect;
  50. titleRect.origin.y += titleRect.size.height;
  51. titleRect.size.height = rect.size.height - titleRect.size.height;
  52. _pageView.frame = titleRect;
  53. }
  54. - (void)select:(NSInteger)index
  55. {
  56. if (index >= 0 && index < _titles.count)
  57. {
  58. _pageView.currentPage = index;
  59. _title.text = _titles[index];
  60. }
  61. }
  62. @end
  63. #endif