我正在剥皮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;
}
请注意,添加黄色背景是为了说明按钮框架的实际大小。为什么我的图像也不是那么大?
这是我的按钮图像: