【问题标题】:Why does setting the tintColor of a UISegmenteControl or UIBarButtonItem disable the button pressing animations?为什么设置 UISegmenteControl 或 UIBarButtonItem 的 tintColor 会禁用按钮按下动画?
【发布时间】:2013-01-24 00:55:23
【问题描述】:

我正在使用以下代码将 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 属性的行,那么它们看起来就不那么好了,但至少它们在视觉上会响应触摸。

为什么会发生这种情况,以及我如何解决它的任何想法?

【问题讨论】:

    标签: iphone objective-c ios cocoa-touch uisegmentedcontrol


    【解决方案1】:

    触摸条形按钮或分段控件时的视觉效果总是使其变暗。由于您的起始色调是黑色,因此按钮不会变暗,因此其外观不会改变。试试另一种颜色,比如深灰色——[UIColor colorWithWhite:0.2 alpha:1],也许吧。

    【讨论】:

    • 谢谢。我想保持 tintColor 黑色并以编程方式将文本的颜色从白色更改为灰色,以指示在按下不同的段时禁用段。你知道有什么好的方法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    相关资源
    最近更新 更多