带有标题的UIButton在异常突出显示时调整图像

时间:2013-08-08 05:55:44

标签: iphone ios

我有一个按钮,1)标题2)背景图像,但突出显示时会异常调整图像。中间有白色区域。有人帮忙吗?

_cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
_cancelButton.adjustsImageWhenHighlighted = YES;
UIImage *cancelImg = [[UIImage imageNamed:@"search_cancel_btn.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0 , 11, 0, 11)];
[_cancelButton setBackgroundImage:cancelImg forState:UIControlStateNormal];
[_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
_cancelButton.titleLabel.font = [UIFont systemFontOfSize:16];
[_cancelButton setTitleColor:[UIColor colorWithHex:0xff666666] forState:UIControlStateNormal];
[_cancelButton setFrame:CGRectMake(264, 9.5, 52, 32)];
[_cancelButton addTarget:self action:@selector(doCancel) forControlEvents:UIControlEventTouchUpInside];
[_topSearchView addSubview:_cancelButton];

abnormal highlighted image

1 个答案:

答案 0 :(得分:0)

只需尝试将这些行添加到相同的代码中:

    _cancelButton.adjustsImageWhenHighlighted = NO;
    [_cancelButton setBackgroundImage:cancelImg forState:UIControlStateHighlighted];
    [_cancelButton setTitle:@"取消" forState:UIControlStateHighlighted];
    [_cancelButton setTitleColor:[UIColor colorWithHex:0xff666666] forState:UIControlStateHighlighted];