简体   繁体   English

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

[英]UIButton with title adjusts image when highlighted abnormally

I have a button with 1) a title 2) a background image, but it adjusts image abnormally when highlighted. 我有一个带有1)标题2)背景图像的按钮,但是突出显示时它会异常调整图像。 It has white area in the middle. 中间有白色区域。 Any one help? 有人帮忙吗?

_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];

高亮图像异常

Just give a try with adding these lines to the same code: 只需尝试将这些行添加到同一代码中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM