UISegmentedControl 的 TintColor 没有反应

发布于 2024-09-28 07:05:35 字数 1204 浏览 3 评论 0原文

来吧!

我几乎一天都在看这个!

我想设置 UISegmentedControl 的色调颜色,但它没有反应...

NSArray *segControlItems = [NSArray arrayWithObjects:
        @"L", 
        @"H",
        @"A",
        nil];
 UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:segControlItems];

 segControl.frame = CGRectMake(0, 0, 90, 30);
 segControl.segmentedControlStyle = UISegmentedControlStyleBar;
 segControl.momentary = YES;
 segControl.tintColor = [UIColor greenColor];


 [segControl addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];

 UIBarButtonItem *segBarItem = [[UIBarButtonItem alloc] initWithCustomView:segControl];
 self.switchView.navigationItem.rightBarButtonItem = segBarItem;

 [segControl release];
 [segBarItem release];

苹果是否制作了一些像“makeUISegmentedControlsDontSetAnyTintColor”这样的属性? 请帮助...

单个按钮有效: http://img257.imageshack.us/i/ schermafbeelding2010102.png/

但是分段后就搞砸了:http://img714。 imageshack.us/i/schemafbeelding2010102.png/

Come oon!

I am almost looking a day at this!

I want to set my tint color of my UISegmentedControl but it doesnt react...

NSArray *segControlItems = [NSArray arrayWithObjects:
        @"L", 
        @"H",
        @"A",
        nil];
 UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:segControlItems];

 segControl.frame = CGRectMake(0, 0, 90, 30);
 segControl.segmentedControlStyle = UISegmentedControlStyleBar;
 segControl.momentary = YES;
 segControl.tintColor = [UIColor greenColor];


 [segControl addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];

 UIBarButtonItem *segBarItem = [[UIBarButtonItem alloc] initWithCustomView:segControl];
 self.switchView.navigationItem.rightBarButtonItem = segBarItem;

 [segControl release];
 [segBarItem release];

Has apple made some property like "makeUISegmentedControlsDontSetAnyTintColor" ore soo?
Please help...

A single button works: http://img257.imageshack.us/i/schermafbeelding2010102.png/

But with the segmented it's messed up: http://img714.imageshack.us/i/schermafbeelding2010102.png/

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

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

发布评论

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

评论(2

一向肩并 2024-10-05 07:05:35

我已经使用 InterfaceBuilder 毫无问题地完成了它。我有三个部分,一些带有标签,一些带有标签+图片,一切正常。

一定是您转换为 BarButtonItem 不起作用。您可以尝试将分段控件添加为导航栏的子视图,而不是将其诱骗到按钮中。

I've done it without problems using InterfaceBuilder. I had three segments, some with labels, some with labels + pictures, all working fine.

It must be your conversion into a BarButtonItem that doesn't work. You could try adding the segmented control as a subview of the nav bar instead of coaxing it into a button.

假装不在乎 2024-10-05 07:05:35

这是一个非常古老的问题,但我今天遇到了这个问题(Xcode 7b5/iOS 9)。就我而言,segmentedControl 是导航栏中的 UIBarButtonItem。我可以通过等待下一个运行循环来设置tintColor,如下所示:

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] init]
(...additional setup...)

UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];    
self.navigationItem.rightBarButtonItem = segmentBarItem;

dispatch_async(dispatch_get_main_queue(), ^{
    segmentedControl.tintColor=[UIColor purpleColor];
});

This is a really old question but I ran into this problem today (Xcode 7b5/iOS 9). In my case the segmentedControl was a UIBarButtonItem in the navBar. I was able to set the tintColor by waiting for the next run loop, like so:

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] init]
(...additional setup...)

UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];    
self.navigationItem.rightBarButtonItem = segmentBarItem;

dispatch_async(dispatch_get_main_queue(), ^{
    segmentedControl.tintColor=[UIColor purpleColor];
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文