简体   繁体   English

调整大小时,UIButton的imageView变为隐藏

[英]UIButton's imageView becomes unhidden when resizing

Consider the following code. 考虑以下代码。 Testing on iOS 7.1 在iOS 7.1上测试

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *button = [[UIButton alloc] init];
    [self.view addSubview:button];
    [button setTitle:@"Test" forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"Default"] forState:UIControlStateNormal];
    button.imageView.hidden = YES;
    [button sizeToFit];
    NSLog(button.imageView.hidden ? @"YES" : @"NO");
    //button's imageView is no longer hidden!
}

Why would sizeToFit unhide the imageView? 为什么sizeToFit取消隐藏imageView?

Please try to hide the image by changing the setImage property to nil like - 请尝试通过将setImage属性更改为nil来隐藏图像,例如-

[button setImage:nil forState:UIControlStateNormal];

instead of setting hidden=YES and than resizing the button manually. 而不是设置hidden = YES,而不是手动调整按钮的大小。

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

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