gpt4 book ai didi

ios - UIBarButtonItem 不显示禁用状态 titleTextAttributes

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

我正在尝试设置禁用 textAttributesUIBarButtonItemUIToolbar .

我像这样创建我的项目:

NSDictionary *enabledAttrs  =  @{ NSFontAttributeName               : font,
NSForegroundColorAttributeName : color };

NSDictionary *disabledAttrs = @{ NSFontAttributeName : font,
NSForegroundColorAttributeName : [UIColor grayColor] };

[item setTitleTextAttributes:enabledAttrs forState:UIControlStateNormal];
[item setTitleTextAttributes:disabledAttrs forState:UIControlStateDisabled];

但是,当我设置 item.enabled = NO , 该按钮被禁用(它不会触发其操作)但它不遵守其 titleTextAttributes ——它仍然以正常状态出现。为什么?

最佳答案

创建 UIButton 并用 UIBarbutton 包装,我认为它应该可以工作。

UIButton *uiButton = [[UIButton alloc] init];
[uiButton setTitleColor: color1 forState: UIControlStateNormal];
[uiButton setTitleColor: color2 forState: UIControlStateDisabled];

UIBarButtonItem *uiBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:uiButton];

关于ios - UIBarButtonItem 不显示禁用状态 titleTextAttributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22217613/

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