Skip to content

Instantly share code, notes, and snippets.

@alexmx
Created April 4, 2017 13:54
Show Gist options
  • Save alexmx/09d3aae065d76b6277b3c0e6a9f92e8f to your computer and use it in GitHub Desktop.
Save alexmx/09d3aae065d76b6277b3c0e6a9f92e8f to your computer and use it in GitHub Desktop.
Set UIButton title icon alignment
- (void)layoutSubviews
{
[super layoutSubviews];
if (self.imageView.image) {
if (self.showIconOnTheRightSide) {
self.titleEdgeInsets = UIEdgeInsetsMake(self.titleEdgeInsets.top, -self.imageView.frame.size.width - self.titleIconSpacing,
self.titleEdgeInsets.bottom, self.imageView.frame.size.width + self.titleIconSpacing);
self.imageEdgeInsets = UIEdgeInsetsMake(self.imageEdgeInsets.top, self.titleLabel.frame.size.width + self.titleIconSpacing,
self.imageEdgeInsets.bottom, -self.titleLabel.frame.size.width - self.titleIconSpacing);
} else {
self.imageEdgeInsets = UIEdgeInsetsMake(0, -self.titleIconSpacing, 0, 0);
self.titleEdgeInsets = UIEdgeInsetsMake(0, self.titleIconSpacing, 0, 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment