Created
March 28, 2013 09:23
-
-
Save halsk/5261890 to your computer and use it in GitHub Desktop.
UIButton をグラデーションにする ref: http://qiita.com/items/200cafdf1ee381453f1a
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
// | |
// IKGrayButton.m | |
// Ikuzo | |
// | |
// Created by Haruyuki Seki on 3/28/13. | |
// | |
#import "IKGrayButton.h" | |
#import "UIColor+Utilities.h" | |
#import <QuartzCore/QuartzCore.h> | |
@implementation IKGrayButton | |
- (id)initWithCoder:(NSCoder *)aDecoder | |
{ | |
self = [super initWithCoder:aDecoder]; | |
[self setTitleColor:[UIColor hexToUIColor:@"666666" alpha:1.0f] forState:UIControlStateNormal]; | |
return self; | |
} | |
// Only override drawRect: if you perform custom drawing. | |
// An empty implementation adversely affects performance during animation. | |
- (void)drawRect:(CGRect)rect | |
{ | |
CAGradientLayer *gradient = [CAGradientLayer layer]; | |
gradient.frame = self.bounds; | |
gradient.colors = @[ | |
(id)[[UIColor hexToUIColor: @"fdfbf3" alpha: 1.0] CGColor], | |
(id)[[UIColor hexToUIColor: @"d7d6d1" alpha: 1.0] CGColor] | |
]; | |
gradient.cornerRadius = 3; | |
gradient.borderColor =[[UIColor hexToUIColor:@"cccccc" alpha:1.0] CGColor]; | |
gradient.borderWidth = 1.0f; | |
[self.layer insertSublayer: gradient atIndex: 0]; | |
} | |
@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
// | |
// UIColor+Utilities.m | |
// Ikuzo | |
// | |
// Created by Haruyuki Seki on 3/28/13. | |
// | |
#import "UIColor+Utilities.h" | |
@implementation UIColor (Utilities) | |
+ (UIColor*) hexToUIColor: (NSString *)hex alpha: (CGFloat)a | |
{ | |
NSScanner *colorScanner = [NSScanner scannerWithString: hex]; | |
unsigned int color; | |
[colorScanner scanHexInt: &color]; | |
CGFloat r = ((color & 0xFF0000) >> 16) / 255.0f; | |
CGFloat g = ((color & 0x00FF00) >> 8) / 255.0f; | |
CGFloat b = (color & 0x0000FF) / 255.0f; | |
return [UIColor colorWithRed: r green: g blue: b alpha: a]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment