-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from johankool/master
Added EFFlatButton
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// EFFlatButton.h | ||
// Egeniq | ||
// | ||
// Created by Johan Kool on 19/6/2012. | ||
// Copyright (c) 2012 Egeniq. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface EFFlatButton : UIButton | ||
|
||
- (UIColor *)backgroundColorForState:(UIControlState)state; | ||
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// EFFlatButton.m | ||
// Egeniq | ||
// | ||
// Created by Johan Kool on 19/6/2012. | ||
// Copyright (c) 2012 Egeniq. All rights reserved. | ||
// | ||
|
||
#import "EFFlatButton.h" | ||
|
||
@interface EFFlatButton () | ||
|
||
@property (nonatomic, strong) UIColor *normalBackgroundColor; | ||
@property (nonatomic, strong) UIColor *highlightedBackgroundColor; | ||
@property (nonatomic, strong) UIColor *selectedBackgroundColor; | ||
@property (nonatomic, strong) UIColor *disabledBackgroundColor; | ||
|
||
@end | ||
|
||
@implementation EFFlatButton | ||
|
||
- (UIColor *)backgroundColorForState:(UIControlState)state { | ||
switch (state) { | ||
case UIControlStateNormal: | ||
return self.normalBackgroundColor; | ||
break; | ||
case UIControlStateHighlighted: | ||
return self.highlightedBackgroundColor; | ||
break; | ||
case UIControlStateSelected: | ||
return self.selectedBackgroundColor; | ||
break; | ||
case UIControlStateDisabled: | ||
return self.disabledBackgroundColor; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return nil; | ||
} | ||
|
||
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state { | ||
switch (state) { | ||
case UIControlStateNormal: | ||
self.normalBackgroundColor = backgroundColor; | ||
break; | ||
case UIControlStateHighlighted: | ||
self.highlightedBackgroundColor = backgroundColor; | ||
break; | ||
case UIControlStateSelected: | ||
self.selectedBackgroundColor = backgroundColor; | ||
break; | ||
case UIControlStateDisabled: | ||
self.disabledBackgroundColor = backgroundColor; | ||
break; | ||
default: | ||
break; | ||
} | ||
[self updateBackgroundColor]; | ||
} | ||
|
||
- (void)setHighlighted:(BOOL)highlighted { | ||
[super setHighlighted:highlighted]; | ||
[self updateBackgroundColor]; | ||
} | ||
|
||
- (void)setSelected:(BOOL)selected { | ||
[super setSelected:selected]; | ||
[self updateBackgroundColor]; | ||
} | ||
|
||
- (void)setEnabled:(BOOL)enabled { | ||
[super setEnabled:enabled]; | ||
[self updateBackgroundColor]; | ||
} | ||
|
||
- (void)updateBackgroundColor { | ||
switch (self.state) { | ||
case UIControlStateNormal: | ||
self.backgroundColor = self.normalBackgroundColor; | ||
break; | ||
case UIControlStateHighlighted: | ||
self.backgroundColor = self.highlightedBackgroundColor; | ||
break; | ||
case UIControlStateSelected: | ||
self.backgroundColor = self.selectedBackgroundColor; | ||
break; | ||
case UIControlStateDisabled: | ||
self.backgroundColor = self.disabledBackgroundColor; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters