为什么设置 UISegmenteControl 或 UIBarButtonItem 的tintColor 会禁用按钮按下动画?
我使用以下代码将 UISegmentedControl 和 UIBarButtonItem 放入 UIToolBar 中:
UISegmentedControl *prevNext = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Previous", @"Next", nil]];
prevNext.segmentedControlStyle = UISegmentedControlStyleBar;
[prevNext addTarget:self action:@selector(prevNextPressed) forControlEvents:UIControlEventValueChanged];
prevNext.tintColor = [UIColor blackColor];
UIBarButtonItem *prevNextButton = [[UIBarButtonItem alloc] initWithCustomView:prevNext];
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(closeKeyboard)];
done.tintColor = [UIColor blackColor];
使用此代码,UISegmentedControl 和 UIBarButtonItem 是静态外观控件,触摸时不会改变其外观。
如果我注释掉设置tintColor属性的行,那么它们看起来不太好,但至少它们在视觉上对触摸做出了响应。
为什么会发生这种情况,以及如何解决这个问题有什么想法吗?
I'm putting a UISegmentedControl and UIBarButtonItem inside of a UIToolBar with the following code:
UISegmentedControl *prevNext = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Previous", @"Next", nil]];
prevNext.segmentedControlStyle = UISegmentedControlStyleBar;
[prevNext addTarget:self action:@selector(prevNextPressed) forControlEvents:UIControlEventValueChanged];
prevNext.tintColor = [UIColor blackColor];
UIBarButtonItem *prevNextButton = [[UIBarButtonItem alloc] initWithCustomView:prevNext];
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(closeKeyboard)];
done.tintColor = [UIColor blackColor];
With this code the UISegmentedControl and UIBarButtonItem are static looking controls that don't change their appearance when touched.
If I comment out the lines that set the tintColor property, then they don't look as good, but at least they visually respond to touch.
Why does this happen, and any ideas on how I can fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
触摸条形按钮或分段控件时的视觉效果总是使其变暗。由于您的起始色调是黑色,因此按钮不会变得更暗,因此其外观不会改变。尝试另一种颜色,例如深灰色 - 也许是
[UIColor colorWithWhite:0.2 alpha:1]
。The visual effect when a bar button or segmented control is touched always darkens it. Since your starting tint color is black, the button can’t get any darker, so its appearance doesn’t change. Try another color, like a dark gray—
[UIColor colorWithWhite:0.2 alpha:1]
, maybe.