Skip to content

Instantly share code, notes, and snippets.

@piersadrian
Last active December 12, 2015 03:08
Show Gist options
  • Save piersadrian/4704045 to your computer and use it in GitHub Desktop.
Save piersadrian/4704045 to your computer and use it in GitHub Desktop.
UIButton *fetchButton = ^(NSString *labelText, CGFloat scalar, UIButtonType type, CGPoint origin) {
UIButton *button = [UIButton buttonWithType:type];
UILabel *label = [[UILabel alloc] init];
[label setText:labelText];
CGSize buttonFrameSize = CGSizeMake([label.text sizeWithFont:label.font].width * scalar * 0.66f,
[label.text sizeWithFont:label.font].height * scalar);
[button setTitle:label.text forState:UIControlStateNormal];
[button setTitleEdgeInsets:UIEdgeInsetsZero];
[button setFrame:CGRectMake(origin.x - buttonFrameSize.width * 0.5,
origin.y - buttonFrameSize.height * 0.5,
buttonFrameSize.width,
buttonFrameSize.height)];
return button;
}(@"Fetch Data", 2.0f, UIButtonTypeRoundedRect,
CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment