Created
February 16, 2012 21:22
-
-
Save wess/1847954 to your computer and use it in GitHub Desktop.
Drawing a complex-ish button with QuartzCore
This file contains hidden or 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
// This is a bit messy right now, wanted to get it looking like i wanted before subclassing | |
// UIButton and making it proper like. | |
// Uses macros and categories from: http://github.com/wess/Additions | |
// | |
CGRect buttonFrame = CGRectInset(SCREEN_BOUNDS, 12.0f, 0.0f); | |
buttonFrame.size.height = 60.0f; | |
buttonFrame.origin.y = fieldFrame.size.height + fieldFrame.origin.y + 20.0f; | |
UIView *buttonView = [UIView viewWithFrame:buttonFrame drawRect:^(UIView *view, CGRect rect) { | |
UIImage *innerShadow = [UIImage imageNamed: @"innershadow.png"]; | |
CALayer *innerShadowLayer = [CALayer layer]; | |
innerShadowLayer.contents = (id)innerShadow.CGImage; | |
innerShadowLayer.contentsCenter = CGRectMake(10.0f/21.0f, 6.0f/21.0f, 1.0f/21.0f, 1.0f/21.0f); | |
innerShadowLayer.frame = rect; | |
innerShadowLayer.masksToBounds = YES; | |
innerShadowLayer.cornerRadius = 6.0f; | |
innerShadowLayer.opacity = 0.6f; | |
[view.layer addSublayer:innerShadowLayer]; | |
}]; | |
buttonView.backgroundColor = CLEAR; | |
buttonView.layer.backgroundColor = HEX_COLOR(@"465F7D").CGColor; | |
buttonView.layer.borderColor = HEX_COLOR(@"304661").CGColor; | |
buttonView.layer.borderWidth = 1.0f; | |
buttonView.layer.cornerRadius = 6.0f; | |
buttonView.layer.shadowColor = WHITE.CGColor; | |
buttonView.layer.shadowOffset = CGSizeMake(0.0f, 1.0f); | |
buttonView.layer.shadowOpacity = 0.3f; | |
buttonView.layer.shadowRadius = 0.0f; | |
[self.view addSubview:buttonView]; | |
UIButton *button = (UIButton *)[UIButton viewWithFrame:CGRectInset(buttonFrame, 5.0f, 5.0f) drawRect:^(UIView *view, CGRect rect) { | |
view.layer.backgroundColor = HEX_COLOR(@"1D75B8").CGColor; | |
CAGradientLayer *gradient = [CAGradientLayer layer]; | |
gradient.frame = CGRectMake(1.0f, 1.0f, rect.size.width - 1.00f, (rect.size.height - 4.0f) - 1.0f); | |
gradient.borderColor = [UIColor colorWithWhite:1.0f alpha:0.2].CGColor; | |
gradient.borderWidth = 1.0f; | |
gradient.cornerRadius = 4.0f; | |
gradient.colors = [NSArray arrayWithObjects: | |
(id)HEX_COLOR(@"79C0DF").CGColor, | |
(id)HEX_COLOR(@"2583C1").CGColor, | |
nil]; | |
[view.layer addSublayer:gradient]; | |
}]; | |
button.backgroundColor = CLEAR; | |
button.layer.borderWidth = 1.0f; | |
button.layer.borderColor = HEX_COLOR(@"364454").CGColor; | |
button.layer.cornerRadius = 4.0f; | |
button.layer.masksToBounds = YES; | |
[button setTitle:@"Save" forState:UIControlStateNormal]; | |
[self.view addSubview:button]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment