I hope, that it's quite simple question, but how I can fit UIButton's frame after following code (project without arc and *.nibs):
_fotosButton = [UIButton buttonWithType: UIButtonTypeCustom];
[_fotosButton setImage: [UIImage imageNamed: @"kino_gallery_normal.png"] forState: UIControlStateNormal];
[_fotosButton setImage: [UIImage imageNamed: @"kino_gallery_highlight.png"] forState: UIControlStateHighlighted];
[_fotosButton setTitle: NSLocalizedString(@"FOTOS", nil) forState: UIControlStateNormal];
[_fotosButton setTitleColor: RGBCOLOR(11.0f, 176.0f, 225.0f) forState: UIControlStateNormal];
[_fotosButton setTitleColor: [UIColor grayColor] forState: UIControlStateDisabled];
[_fotosButton.titleLabel setFont:TTSTYLEVAR(kinoFont10)];
[_fotosButton sizeToFit];
[self updateButtonInsets:_fotosButton];
[self addSubview: _fotosButton];
- (void) updateButtonInsets:(UIButton*) button {
CGSize imageSize = button.imageView.frame.size;
CGSize titleSize = button.titleLabel.frame.size;
button.titleEdgeInsets = UIEdgeInsetsMake(0.0f, -imageSize.width, -imageSize.height, 0.0);
titleSize = button.titleLabel.frame.size;
button.imageEdgeInsets = UIEdgeInsetsMake(-titleSize.height, 0.0f, 0.0f, -titleSize.width);
}
This is a result of my code:
So, how can I fit frame (green area) to the content(title+image) without unnecessary paddings. I can't hardcode value of button's frame, because app use Localisation. Thank you!