如何禁用与 UIBarButtonItem 的用户交互?
How to disable userinteraction with UIBarButtonItem?
当用户按下条形按钮时,它会将颜色更改为灰色。但是当状态为 pressed
时,条形按钮的颜色不应该改变。我遇到了与 this question 一样的问题,但从未得到解决,而且每个答案都不起作用。没有setUserInteractionEnabled
属性。但是禁用整个栏按钮会给栏按钮带来 alpha 效果,我不想这样做。
有什么建议吗?
你是对的,没有优雅的解决方案。最好的方法是在工具栏中使用 UIButton。查看此答案中的编辑部分:How do I remove UIBarButtonItem glow programtically?
我有类似的问题,我通过为 UIControlStateNormal 和 UIControlStateDisabled.Then 禁用栏按钮设置相同的图像解决了它。
UIImage *buttonImage = [UIImage imageNamed:@"ic_launcher.png"];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
[aButton setImage:buttonImage forState:UIControlStateDisabled];
aButton.frame = CGRectMake(0.0,0.0,50,50);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:aButton];
backButton.enabled = NO;
self.navigationItem.leftBarButtonItem = backButton;
当用户按下条形按钮时,它会将颜色更改为灰色。但是当状态为 pressed
时,条形按钮的颜色不应该改变。我遇到了与 this question 一样的问题,但从未得到解决,而且每个答案都不起作用。没有setUserInteractionEnabled
属性。但是禁用整个栏按钮会给栏按钮带来 alpha 效果,我不想这样做。
有什么建议吗?
你是对的,没有优雅的解决方案。最好的方法是在工具栏中使用 UIButton。查看此答案中的编辑部分:How do I remove UIBarButtonItem glow programtically?
我有类似的问题,我通过为 UIControlStateNormal 和 UIControlStateDisabled.Then 禁用栏按钮设置相同的图像解决了它。
UIImage *buttonImage = [UIImage imageNamed:@"ic_launcher.png"];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
[aButton setImage:buttonImage forState:UIControlStateDisabled];
aButton.frame = CGRectMake(0.0,0.0,50,50);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:aButton];
backButton.enabled = NO;
self.navigationItem.leftBarButtonItem = backButton;