UISegmentedControl in Mail application

How to get a UISegmentedControl that is similar to the one in the Mail application, so that it is the same as the UIToolbar buttons (as if both segments were in the selected state).

I want to use a segmented control just like Mail.

(on the iPad, so gray is not blue)

+6
iphone ipad uitoolbar uisegmentedcontrol
source share
5 answers

The style I'm looking for is undocumented: it's style 4. It looks like it controls up / down: http://media.mobilemeandering.com/wp-content/uploads/2010/04/ipad-mail-message-2.png ( not my picture by the way)

Basically, all segments look highlighted, they are designed for instant clicks, and these are effectively several toolbar buttons pushed together. Therefore, it cannot be installed in IB, but must be installed in code or manually in the nib / xib file by opening nib as a text file.

+1
source share

This is the code from Apple Sample codes ... NavBar and both images used in the code .. you can get the same opinion as the mail application.

alt textalt 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]; 
+6
source share

You are looking for the tintColor property!

When you use UISegmentedControl , you can change the hue color to any color you can think of. So, if you added a UISegmentedControl to the Interface Builder, you would put it in your method - (void)viewWillAppear:(BOOL)animated as such (assuming you connected it to @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 that I set in the above code example, but you can literally color the UISegmentedController with whatever color you want (or make it transparent as you would like), so it's just a matter of finding RGBA values ​​that look perfect for you.

Remember that Apple documents 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. 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

+3
source share

I don’t know exactly what you mean .. but I believe that UISegmentedControlStyleBar as segmentedControlStyle can be.

 segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar 

You can also set this property to IB! (This property is called "style")

+1
source share

I'm not sure that I understand exactly what you are trying to do, but I will give him a chance.

The solution is not obvious, you need to use the UISearchDisplayController to get the corresponding UISearchBar and UISegmentedControl.

Example Example TableSearch for example.

0
source share

All Articles