gpt4 book ai didi

iphone - UIButton setTitleColor :forState: question

转载 作者:太空狗 更新时间:2023-10-30 03:18:49 34 4
gpt4 key购买 nike

为什么下面的代码可以工作...

[signInBtn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[signInBtn setTitleColor:[UIColor blackColor] forState:UIControlStateDisabled];

虽然这不是?

[signInBtn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted|UIControlStateDisabled];

最佳答案

我知道这是一个老问题,但这些答案并不正确。

当你分别设置每一个时,你说的是 state 属性应该是 UIControlStateHighlightedUIControlStateDisabled 但不能两者都是

当您按位或将它们放在一起时,您声明它们必须在 state 属性中设置。意思是 UIControlStateHighlightedUIControlStateDisabledstate 属性中设置。

下面的示例代码完美地说明了我的观点。如果您不同意,请自行运行。

[button setTitle:@"highlighted and selected" forState:UIControlStateHighlighted | UIControlStateSelected];
[button setTitle:@"Highlighted only" forState:UIControlStateHighlighted];
[button setTitle:@"Selected only" forState:UIControlStateSelected];
[button setTitle:@"Normal" forState:UIControlStateNormal];

NSLog(@"Normal title: %@", [[button titleLabel] text]); // prints title: Normal

[button setSelected:YES];

NSLog(@"Selected title: %@", [[button titleLabel] text]); // prints title: Selected only

[button setSelected:NO];
[button setHighlighted:YES];

NSLog(@"highlighted title: %@", [[button titleLabel] text]); // prints title: Highlighted only

[button setSelected:YES];

NSLog(@"highlighted and selected title: %@", [[button titleLabel] text]); // prints title: highlighted and selected

关于iphone - UIButton setTitleColor :forState: question,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4370466/

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