UISegmentedControl 选定的色调未显示

发布于 2024-08-15 10:28:43 字数 185 浏览 6 评论 0原文

当我将整个导航栏设置为黑色时,通常在所选按钮的 UISegmentedControl 上显示的色调不会显示(self.navigationController.navigationBar.tintColor = [UIColor blackColor];< /代码>)。

这是一个错误还是我遗漏了什么?

The tint that usually shows on a UISegmentedControl on the selected button isn't showing when I set the whole nav bar to black (self.navigationController.navigationBar.tintColor = [UIColor blackColor];).

Is this a bug or something I'm missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

白芷 2024-08-22 10:28:43

为了显示色调颜色,有几个要求:

segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

tintColor 必须工作。

您还提到您已将 tintColor 设置为 [UIColor blackColor]。不幸的是,UISegmentedControl 将始终以较深颜色显示所选段,而不是较亮的颜色。尝试将 tintColor 设置为 [UIColor darkGrayColor],您应该能够看到所选片段的颜色发生变化。

In order for the tint color to show, there are a couple of requirements:

segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

It's required for the tintColor to work.

You also mention that you have the tintColor set to [UIColor blackColor]. Unfortunately, the UISegmentedControl will always display the selected segment with a darker color, never a lighter. Try setting your tintColor to [UIColor darkGrayColor] and you should be able to see the selected segment change color.

倾听心声的旋律 2024-08-22 10:28:43

您是否尝试过单独设置分段控件的色调?

segmentedControl.tintColor = self.navigationController.navigationBar.tintColor;

Have you tried setting the tint on the segmented control separately?

segmentedControl.tintColor = self.navigationController.navigationBar.tintColor;
煮茶煮酒煮时光 2024-08-22 10:28:43

尝试使用色调[UIColor colorWithWhite:80.0/255.0 alpha:1.0]
这使得黑色变得不那么黑,并且允许选择的片段在选择后变得更暗。您可以根据需要设置白色分量。

示例代码:

UISegmentedControl *aSegmentedControl = [[UISegmentedControl alloc] initWithItems:arrItems];
aSegmentedControl.frame = CGRectMake(55, 382, 210, 32);
aSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
aSegmentedControl.selectedSegmentIndex = 0;
aSegmentedControl.tintColor = [UIColor colorWithWhite:80.0/255.0 alpha:1.0];

Try using tint color [UIColor colorWithWhite:80.0/255.0 alpha:1.0].
This makes the black color less black and allows the selected segment to become darker after selection. You can set the white component as suitable.

Sample code:

UISegmentedControl *aSegmentedControl = [[UISegmentedControl alloc] initWithItems:arrItems];
aSegmentedControl.frame = CGRectMake(55, 382, 210, 32);
aSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
aSegmentedControl.selectedSegmentIndex = 0;
aSegmentedControl.tintColor = [UIColor colorWithWhite:80.0/255.0 alpha:1.0];
听风吹 2024-08-22 10:28:43

在 iPhone 3.0 上,如果您想在 NavigationController 中添加分段控件,请先执行此操作,然后在执行此操作后更改色调颜色。

On iphone 3.0, if you want add the Segmented Control in a NavigationController, do that first and change the tintcolor after u did that.

智商已欠费 2024-08-22 10:28:43

如果您在导航栏上看到不同的色调,您可能还需要使用 uisegmentedcontrol 上的瞬时属性。

segmentedControl.momentary=YES;

这会清除控件的突出显示色调。

If you are seeing different tint colors on the nav bar, you may also want to use the momentary property on your uisegmentedcontrol.

segmentedControl.momentary=YES;

This clears the highlight tint from the control.

不可一世的女人 2024-08-22 10:28:43

在属性检查器中将分段控件样式更改为条形或边框。就这样。

Change the segmented control style to Bar or Bezeled in the Attributes Inspector. That's all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文