0

我正在剥皮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;
}

请注意,添加黄色背景是为了说明按钮框架的实际大小。为什么我的图像也不是那么大? 在此处输入图像描述

这是我的按钮图像:在此处输入图像描述

4

1 回答 1

1

我在 Photoshop 中查看了您的按钮图像,看起来图像周围有透明度,并且图像的大小小于画布。图像只有 43x44 像素,周围有透明区域。

我已经剪掉了透明区域。试试这张图片。

在此处输入图像描述

于 2012-12-07T19:25:08.700 回答