簡體   English   中英

帶有標題的UIButton在異常突出顯示時調整圖像

[英]UIButton with title adjusts image when highlighted abnormally

我有一個帶有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];

高亮圖像異常

只需嘗試將這些行添加到同一代碼中:

    _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