スキニングUIButtons
を行っていますが、ボタンの幅が画像で表示される幅よりもはるかに広いことがわかりました。
フレームとサイズを指定して、以下のボタン メソッドを呼び出します。
CGSize buttonSize = CGSizeMake(240, 64);
+ (UIButton *)buttonWithThemeAndFrame:(CGRect )frame title:(NSString *)title target:(id)target selector:(SEL)selector {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:frame];
button.backgroundColor = [UIColor yellowColor];
NSString *defaultName = @"button_main_up";
NSString *highlighted = @"button_main_down";
[button setBackgroundImage:[[UIImage imageNamed:defaultName] stretchableImageWithLeftCapWidth:12 topCapHeight:12.0] forState:UIControlStateNormal];
[button setBackgroundImage:[[UIImage imageNamed:highlighted] stretchableImageWithLeftCapWidth:12 topCapHeight:12.0] forState:UIControlStateHighlighted];
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:12.0]];
[button setTitle:title forState:UIControlStateNormal];
[button setTitleColor:[UIColor colorWithWhite:1.0 alpha:0.5] forState:UIControlStateDisabled];
button.titleLabel.shadowOffset = CGSizeMake(0.0, -1.0);
button.titleLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
[button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
button.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
return button;
}
ボタンのフレームの実際のサイズを示すために黄色の背景が追加されていることに注意してください。私の画像もそのサイズではないのはなぜですか?
これが私のボタン画像です: