gpt4 book ai didi

ios - UIButton - 复选标记未显示

转载 作者:行者123 更新时间:2023-12-01 17:50:50 25 4
gpt4 key购买 nike

我正在尝试创建一个 uibutton 作为复选框。一切正常,但 View :我正在设置单击时更改 View 。当它应该不显示复选标记时很好,但是当我需要显示复选标记时,它不起作用。这就是发生的事情:

image with no checkmark
image with checkmark

这是代码:

- (void)viewDidLoad {
[super viewDidLoad];

[self.myButton setTitle:@"\u2610" forState:UIControlStateNormal];
[self.myButton setTitle:@"\u2610" forState:UIControlStateHighlighted];
[self.myButton setTitle:@"\u2610" forState:UIControlStateDisabled];
[self.myButton setTitle:@"\u2610" forState:UIControlStateNormal];
[self.myButton setTitle:@"\u2611" forState:UIControlStateSelected];
}

//action sent to the button when touched up inside
- (IBAction)moneyButtonClicked:(id)sender {
UIButton *button = (UIButton *)sender;
button.selected = !button.selected;
}

怎么了?

问候!

最佳答案

我只是创建一个新项目并添加以下代码。它就像 gif 显示的那样工作。你可以做一个比较。

enter image description here

- (void)viewDidLoad {
[super viewDidLoad];
self.checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.checkButton addTarget:self action:@selector(moneyButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.checkButton.frame = CGRectMake(50, 50, 50, 50);
self.checkButton.titleLabel.textColor = [UIColor redColor];
self.checkButton.backgroundColor = [UIColor yellowColor];
[self.checkButton setTitle:@"\u2610" forState:UIControlStateNormal];
[self.checkButton setTitle:@"\u2611" forState:UIControlStateSelected];
[self.view addSubview:self.checkButton];
}

- (IBAction)moneyButtonClicked:(id)sender {
UIButton *button = (UIButton *)sender;
button.selected = !button.selected;
}

关于ios - UIButton - 复选标记未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31925799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com