2020#define kTextEdgeInsets 10 .f
2121
2222// Customizable color
23- #define kBackgroundColor [UIColor blackColor ]
24- #define kHighlightColor [UIColor lightGrayColor ]
25- #define kDividerColor [UIColor whiteColor ]
26- #define kTextColor [UIColor whiteColor ]
23+ #define kDefaultBackgroundColor [UIColor blackColor ]
24+ #define kDefaultHighlightColor [UIColor lightGrayColor ]
25+ #define kDefaultDividerColor [UIColor whiteColor ]
26+ #define kDefaultTextColor [UIColor whiteColor ]
2727
2828@interface MenuPopOverView ()
2929
@@ -50,18 +50,22 @@ @implementation MenuPopOverView
5050@synthesize buttons = _buttons;
5151@synthesize dividers = _dividers;
5252@synthesize pageButtons = _pageButtons;
53+ @synthesize popOverBackgroundColor = _popOverBackgroundColor;
54+ @synthesize popOverHighlightColor = _popOverHighlightColor;
55+ @synthesize popOverDividerColor = _popOverDividerColor;
56+ @synthesize popOverTextColor = _popOverTextColor;
5357
54- - (id )init {
55- if (self = [super init ]) {
56- self.backgroundColor = [UIColor clearColor ];
57- }
58- return self;
58+ -(instancetype )init {
59+
60+ return [self initWithFrame: CGRectZero];
5961}
6062
61- - (id )initWithFrame : (CGRect)frame {
63+ -(instancetype )initWithFrame : (CGRect)frame {
64+
6265 if (self = [super initWithFrame: frame]) {
6366 self.backgroundColor = [UIColor clearColor ];
6467 }
68+
6569 return self;
6670}
6771
@@ -87,9 +91,9 @@ - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view withStrings:(N
8791 CGSize textSize = [string sizeWithAttributes: @{NSFontAttributeName : kTextFont }];
8892 UIButton *textButton = [[UIButton alloc ] initWithFrame: CGRectMake (0 , 0 , textSize.width + 2 * kTextEdgeInsets , kButtonHeight )];
8993 textButton.enabled = NO ;
90- textButton.backgroundColor = kBackgroundColor ;
94+ textButton.backgroundColor = self. popOverBackgroundColor ;
9195 textButton.titleLabel .font = kTextFont ;
92- textButton. titleLabel . textColor = kTextColor ;
96+ [ textButton setTitleColor: self .popOverTextColor forState: UIControlStateNormal] ;
9397 textButton.titleLabel .textAlignment = NSTextAlignmentCenter;
9498 [textButton setTitle: string forState: UIControlStateNormal];
9599 [textButton addTarget: self action: @selector (didTapButton: ) forControlEvents: UIControlEventTouchUpInside];
@@ -228,7 +232,7 @@ - (float)reArrangeButtons:(NSArray *)buttons {
228232 // add disabled rightArrowBtn
229233 UIButton *rightArrowBtn = [self getControlButton: YES ];
230234 rightArrowBtn.enabled = NO ;
231- rightArrowBtn. titleLabel . textColor = [UIColor lightGrayColor ];
235+ [ rightArrowBtn setTitleColor: [UIColor lightGrayColor ] forState: UIControlStateNormal ];
232236 CGRect rightArrowFrame = rightArrowBtn.frame ;
233237 rightArrowFrame.origin .x = currentX;
234238 rightArrowBtn.frame = rightArrowFrame;
@@ -405,7 +409,7 @@ - (void)tapped:(UITapGestureRecognizer *)tap {
405409}
406410
407411- (void )didTapButton : (UIButton *)sender {
408- sender.backgroundColor = kBackgroundColor ;
412+ sender.backgroundColor = self. popOverBackgroundColor ;
409413
410414 NSUInteger index = [self .buttons indexOfObject: sender];
411415 if (index != NSNotFound && self.delegate && [self .delegate respondsToSelector: @selector (popoverView:didSelectItemAtIndex: )]) {
@@ -450,7 +454,7 @@ - (void)didTapLeftArrowButton:(UIButton *)sender {
450454 for (UIButton *b in [self .pageButtons objectAtIndex: _pageIndex]) {
451455 b.enabled = YES ;
452456 }
453- sender.backgroundColor = kBackgroundColor ;
457+ sender.backgroundColor = self. popOverBackgroundColor ;
454458
455459 CGRect contentFrame = self.contentView .frame ;
456460 contentFrame.origin .x += popoverMaxWidth;
@@ -473,9 +477,9 @@ - (void)didTapRightArrowButton:(UIButton *)sender {
473477 b.enabled = YES ;
474478 }
475479 ((UIButton *)[[self .pageButtons lastObject ] lastObject ]).enabled = NO ;
476- ((UIButton *)[[self .pageButtons lastObject ] lastObject ]). titleLabel . textColor = [UIColor lightGrayColor ];
480+ [ ((UIButton *)[[self .pageButtons lastObject ] lastObject ]) setTitleColor: [UIColor lightGrayColor ] forState: UIControlStateNormal ];
477481
478- sender.backgroundColor = kBackgroundColor ;
482+ sender.backgroundColor = self. popOverBackgroundColor ;
479483
480484 CGRect contentFrame = self.contentView .frame ;
481485 contentFrame.origin .x -= popoverMaxWidth;
@@ -489,9 +493,9 @@ - (void)didTapRightArrowButton:(UIButton *)sender {
489493- (UIButton *)getControlButton : (BOOL )rightArrow {
490494 UIButton *res = [[UIButton alloc ] initWithFrame: CGRectMake (0 , 0 , kRightButtonWidth , kButtonHeight )];
491495 res.enabled = NO ;
492- res.backgroundColor = kBackgroundColor ;
496+ res.backgroundColor = self. popOverBackgroundColor ;
493497 res.titleLabel .font = kTextFont ;
494- res. titleLabel . textColor = kTextColor ;
498+ [ res setTitleColor: self .popOverTextColor forState: UIControlStateNormal] ;
495499 res.titleLabel .textAlignment = NSTextAlignmentCenter;
496500 if (rightArrow) {
497501 // unicode for right arrow
@@ -509,11 +513,11 @@ - (UIButton *)getControlButton:(BOOL)rightArrow {
509513}
510514
511515- (void )changeBackgroundColor : (UIButton *)sender {
512- sender.backgroundColor = kHighlightColor ;
516+ sender.backgroundColor = self. popOverHighlightColor ;
513517}
514518
515519- (void )resetBackgroundColor : (UIButton *)sender {
516- sender.backgroundColor = kBackgroundColor ;
520+ sender.backgroundColor = self. popOverBackgroundColor ;
517521}
518522
519523#pragma mark - rotation
@@ -620,10 +624,74 @@ - (void)drawRect:(CGRect)rect {
620624 rect.origin .y += self.contentView .frame .origin .y ;
621625
622626 UIBezierPath *dividerPath = [UIBezierPath bezierPathWithRect: rect];
623- [kDividerColor setFill ];
627+ [self .popOverDividerColor setFill ];
624628 [dividerPath fill ];
625629 }
626630 }
627631}
628632
633+ -(void )setPopOverBackgroundColor : (UIColor *)popOverBackgroundColor {
634+
635+ _popOverBackgroundColor = popOverBackgroundColor;
636+ }
637+
638+ -(UIColor *)popOverBackgroundColor {
639+
640+ if (_popOverBackgroundColor == nil ) {
641+ return kDefaultBackgroundColor ;
642+ }
643+
644+ else {
645+ return _popOverBackgroundColor;
646+ }
647+ }
648+
649+ -(void )setPopOverHighlightColor : (UIColor *)popOverHighlightColor {
650+
651+ _popOverHighlightColor = popOverHighlightColor;
652+ }
653+
654+ -(UIColor *)popOverHighlightColor {
655+
656+ if (_popOverHighlightColor == nil ) {
657+ return kDefaultHighlightColor ;
658+ }
659+
660+ else {
661+ return _popOverHighlightColor;
662+ }
663+ }
664+
665+ -(void )setPopOverDividerColor : (UIColor *)popOverHighlightColor {
666+
667+ _popOverDividerColor = popOverHighlightColor;
668+ }
669+
670+ -(UIColor *)popOverDividerColor {
671+
672+ if (_popOverDividerColor == nil ) {
673+ return kDefaultDividerColor ;
674+ }
675+
676+ else {
677+ return _popOverDividerColor;
678+ }
679+ }
680+
681+ -(void )setPopOverTextColor : (UIColor *)popOverTextColor {
682+
683+ _popOverTextColor = popOverTextColor;
684+ }
685+
686+ -(UIColor *)popOverTextColor {
687+
688+ if (_popOverTextColor == nil ) {
689+ return kDefaultTextColor ;
690+ }
691+
692+ else {
693+ return _popOverTextColor;
694+ }
695+ }
696+
629697@end
0 commit comments