iphone - 邮件应用程序中的 UISegmentedControl

标签 iphone ipad uitoolbar uisegmentedcontrol

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

我想使用分段控件来实现与 Mail 完全相同的目的。

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

最佳答案

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

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];

关于iphone - 邮件应用程序中的 UISegmentedControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3772170/

相关文章:

css - 响应式网页设计.. Ipad 上不需要的右填充/边距

ios - 以编程方式创建 UIToolbar 后 UIBarButtonItems 未显示?

iphone - 如何使用 CALayer : Trying to draw a Layer in my Application

iphone - 使用未声明的标识符 - 核心数据

iphone - Scrollview 在dismissViewControllerAnimated 后没有滚动

ios - Expo React iOS 构建在 iPad 中无法正常运行

iOS MDM 创建信任问题

iphone - 在 objective-c 中只从磁盘读取文件的一部分

iOS 为什么将 ToolBar 间隙移至键盘

ios - iPad 屏幕顶部的多个栏