我在一个新项目中测试它。在情节提要中,我创建了一个标记为 B 的 UIButton,并通过代码创建了一个标记为 C 的 UIButton。我在代码中设置了 b 按钮背景图像,它不起作用。我不知道为什么,我猜 Xcode 13 有所作为?这是我的代码:
- (void)viewDidLoad {
[self.bButton setBackgroundImage:[UIImage imageNamed:@"0"] forState:UIControlStateNormal];// not work
UIButton *cButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
[cButton setTitle:@"C" forState:UIControlStateNormal];
[self.view addSubview:cButton];
[cButton setBackgroundImage:[UIImage imageNamed:@"0"] forState:UIControlStateNormal];
}
在故事板上