Skip to content

Instantly share code, notes, and snippets.

@Blankwonder
Created September 16, 2013 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blankwonder/6579924 to your computer and use it in GitHub Desktop.
Save Blankwonder/6579924 to your computer and use it in GitHub Desktop.
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
CGFloat textWidth = [button.currentTitle sizeWithFont:button.titleLabel.font].width;
CGFloat imageWidth = button.currentImage.size.width;
CGFloat buttonWidth = button.frame.size.width;
CGFloat contentWidth = textWidth + 5 + imageWidth;
[button setTitleEdgeInsets:UIEdgeInsetsMake(0, - imageWidth + (buttonWidth - contentWidth) / 2.0f, 0, 0)];
[button setImageEdgeInsets:UIEdgeInsetsMake(2, contentWidth / 2.0f + buttonWidth / 2.0f - imageWidth, 0, 0)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment