邮件应用程序中的 UISegmentedControl

发布于 2024-09-24 08:53:41 字数 145 浏览 4 评论 0原文

如何获得一个类似于邮件应用程序中的 UISegmentedControl,以便它与 UIToolbar 按钮颜色相同(就好像两个段都处于选定状态一样)。

我想使用分段控件来达到与邮件完全相同的目的。

(在 iPad 上,所以是灰色而不是蓝色)

How do I get a UISegmentedControl that is like the one in the Mail App, so that it is the same colour as UIToolbar buttons (as if both segments were in the selected state).

I want to use the segmented control for exactly the same purpose as Mail.

(on the iPad, so a grey not blue color)

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

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

发布评论

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

评论(5

孤者何惧 2024-10-01 08:53:41

这是来自 Apple 示例代码的代码...导航栏以及代码中使用的两个图像..
您应该能够获得与邮件应用程序完全相同的视图。

替代文本

// "Segmented" control to the right
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
                                            [NSArray arrayWithObjects:
                                                [UIImage imageNamed:@"up.png"],
                                                [UIImage imageNamed:@"down.png"],
                                             nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 90, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;

defaultTintColor = [segmentedControl.tintColor retain];    // keep track of this for later

UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];

self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];

This is code from Apple Sample codes... NavBar and both the images used in the code..
you shoud be able to get exact same view as mail App.

alt text alt text

// "Segmented" control to the right
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
                                            [NSArray arrayWithObjects:
                                                [UIImage imageNamed:@"up.png"],
                                                [UIImage imageNamed:@"down.png"],
                                             nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 90, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;

defaultTintColor = [segmentedControl.tintColor retain];    // keep track of this for later

UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];

self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
丶视觉 2024-10-01 08:53:41

您正在寻找 tintColor 属性!

当您使用UISegmentedControl时,您可以将其色调更改为您可以想象的任何颜色。因此,如果您在 Interface Builder 中添加了 UISegmentedControl,那么您可以在 - (void)viewWillAppear:(BOOL)animated 方法中设置它的样式(假设您已将其连接到 @synthesized ivar:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // Set the tintColor to match the navigation bar
    self.mySegmentedControl.tintColor = [UIColor colorWithRed:.94 green:.94 blue:.94 alpha:1];

    ... do whatever else in your viewWillAppear ...
}

现在显然你会想要使用我在上面的示例代码中放入的红色、绿色、蓝色和 alpha 颜色,但是你可以从字面上为 UISegmentedController 着色任何你想要的颜色(或者使其像你想要的那样透明) ),因此只需找到适合您的 RGBA 值即可。

请记住,根据 Apple 文档,此属性的默认值为 nil(无颜色),仅当 UISegmentedControl 的样式时才使用此属性。分段控件是UISegmentedControlStyleBar。

祝你好运!

You seek the tintColor property!

When you use a UISegmentedControl you can change its tint color to any color you can dream up. So, if you added the UISegmentedControl in Interface Builder then you would style it in your - (void)viewWillAppear:(BOOL)animated method as such (assuming you had it hooked up to a @synthesized ivar:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // Set the tintColor to match the navigation bar
    self.mySegmentedControl.tintColor = [UIColor colorWithRed:.94 green:.94 blue:.94 alpha:1];

    ... do whatever else in your viewWillAppear ...
}

Now obviously you will want to play with the red, green, blue, and alpha's that I've put in the sample code above, but you can literally tint the UISegmentedController any color you would like (or make it as transparent as you would like), so it's just a matter of finding the RGBA values that look perfect to you.

Remember that per Apple's docs that the default value of this property is nil (no color). UISegmentedControl uses this property only if the style of the segmented control is UISegmentedControlStyleBar.

Good luck!

染火枫林 2024-10-01 08:53:41

我不知道你的意思..但我相信“UISegmentedControlStyleBar”可能是segmentedControlStyle。

segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar

您也可以在 IB 中设置此属性! (这是称为“样式”的属性)

I dont know exactly what you mean.. but i believe the "UISegmentedControlStyleBar" as segmentedControlStyle could it be.

segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar

You can set this property in the IB too! (It's the property called "style")

路弥 2024-10-01 08:53:41

我正在寻找的样式没有记录:它是样式 4。
看起来他在这里向上/向下控制: http://media.mobilemeandering.com/wp-content/uploads/2010/04/ipad-mail-message-2.png
(顺便说一句,不是我的图像)

它基本上使所有部分看起来都被选中,它用于瞬时推动,并且实际上是将多个工具栏按钮推到一起。
因此它不能在 IB 中设置,而必须在代码中设置或通过将 nib 作为文本文件打开来在 nib/xib 文件中手动设置。

The style I'm looking for is undocumented: it is style 4.
It looks like he up/down control here: http://media.mobilemeandering.com/wp-content/uploads/2010/04/ipad-mail-message-2.png
(not my image btw)

It basically makes all segments look selected, it's intended for momentary pushes, and is effectively multiple tool bar buttons pushed up together.
So it can't be set in IB but must be set in code or manually in the nib/xib file, by opening the nib as a text file.

独自唱情﹋歌 2024-10-01 08:53:41

我不确定我是否完全理解你想要做什么,但我会尝试一下。

解决方案并不明显,您需要使用 UISearchDisplayController 以获得匹配的 UISearchBar 和 UISegmentedControl。

有关示例,请参阅 TableSearch 示例代码。

I'm not sure I exactly understand what you're trying to do, but I'll give it a shot.

The solution is not obvious, you need to use a UISearchDisplayController in order to get a matching UISearchBar and UISegmentedControl.

See the TableSearch sample code for an example.

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