代码之家  ›  专栏  ›  技术社区  ›  Jonathan.

邮件应用程序中的UISegmentedControl

  •  6
  • Jonathan.  · 技术社区  · 14 年前

    如何获得与Mail应用程序中的控件类似的UISegmentedControl,使其与UIToolbar按钮的颜色相同(就像两个段都处于选中状态一样)。

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

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

    5 回复  |  直到 14 年前
        1
  •  6
  •   k-thorat    14 年前

    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];
    
        2
  •  3
  •   Neal L    14 年前

    你在寻找 tintColor 财产!

    UISegmentedControl 你可以把它的色调改成任何你想得到的颜色。因此,如果您在Interface Builder中添加了UISegmentedControl,那么您可以在 - (void)viewWillAppear:(BOOL)animated

    - (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值。

    记住,根据苹果的文档 the default value of this property is nil (no color). UISegmentedControl uses this property only if the style of the segmented control is UISegmentedControlStyleBar.

        3
  •  1
  •   user289841 user289841    14 年前

    我不知道你的确切意思。。但我相信“UISegmentedControlStyleBar”作为segmentedControlStyle是可以的。

    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar
    

    您也可以在IB中设置此属性!(这是一个叫做“风格”的属性)

        4
  •  1
  •   Jonathan.    14 年前

    我要找的样式没有文档记录:它是样式4。 看起来他在这里上下控制: http://media.mobilemeandering.com/wp-content/uploads/2010/04/ipad-mail-message-2.png

    它基本上使所有的部分看起来都是选中的,它的目的是瞬间按下,并有效地将多个工具栏按钮推到一起。 所以它不能在IB中设置,但必须在代码中设置,或者在nib/xib文件中手动设置,方法是将nib作为文本文件打开。

        5
  •  0
  •   christo16    14 年前

    我不确定我是否完全明白你想做什么,但我会试试看。

    解决方案不明显,需要使用 UISearchDisplayController

    看到了吗 TableSearch 示例代码。