Skip to content

Instantly share code, notes, and snippets.

@vmus
Last active November 2, 2018 02:26
Show Gist options
  • Save vmus/559aa4be56807a8092ee to your computer and use it in GitHub Desktop.
Save vmus/559aa4be56807a8092ee to your computer and use it in GitHub Desktop.
(http://stackoverflow.com/questions/22345046/customize-button-shape-in-ios-7-1) Sub class the button and try which shape you want.... (answered Mar 12 at 10:06 by Spynet)
#import "YourButton.h"
#import <QuartzCore/QuartzCore.h>
@implementation YourButton
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)awakeFromNib
{
[super awakeFromNib];
CALayer *mask = [CALayer layer];
mask.contents = (id)[[UIImage imageNamed:@"ge.png"] CGImage]; // ge is the black & white png image
CGSize size = self.frame.size;
mask.frame = CGRectMake(0, 0, size.width, size.height);
self.layer.mask = mask;
[self.layer setMasksToBounds:YES];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment