Skip to content

Instantly share code, notes, and snippets.

@leilee
Last active July 24, 2017 13:51
Show Gist options
  • Select an option

  • Save leilee/105ed5ea71e4ec266c41 to your computer and use it in GitHub Desktop.

Select an option

Save leilee/105ed5ea71e4ec266c41 to your computer and use it in GitHub Desktop.
UIButton place image & title vertical
// the space between the image and text
CGFloat spacing = 6.0;
// lower the text and push it left so it appears centered
// below the image
CGSize imageSize = button.imageView.image.size;
button.titleEdgeInsets = UIEdgeInsetsMake(
0.0, - imageSize.width, - (imageSize.height + spacing), 0.0);
// raise the image and push it right so it appears centered
// above the text
CGSize titleSize = [button.titleLabel.text sizeWithAttributes:@{NSFontAttributeName: button.titleLabel.font}];
button.imageEdgeInsets = UIEdgeInsetsMake(
- (titleSize.height + spacing), 0.0, 0.0, - titleSize.width);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment