0

我有一个带有 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];

异常高亮图像

4

1 回答 1

0

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

    _cancelButton.adjustsImageWhenHighlighted = NO;
    [_cancelButton setBackgroundImage:cancelImg forState:UIControlStateHighlighted];
    [_cancelButton setTitle:@"取消" forState:UIControlStateHighlighted];
    [_cancelButton setTitleColor:[UIColor colorWithHex:0xff666666] forState:UIControlStateHighlighted];
于 2013-08-08T06:23:09.857 回答