非常に単純な質問であることを願っていますが、次のコード (arc と *.nibs を使用しないプロジェクト) の後に UIButton のフレームをどのように合わせることができますか?
_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);
}
これは私のコードの結果です:
では、不要なパディングなしでフレーム (緑色の領域) をコンテンツ (タイトル + 画像) に合わせるにはどうすればよいでしょうか。アプリはローカリゼーションを使用するため、ボタンのフレームの値をハードコーディングできません。ありがとうございました!