Search code examples
iosipaduitabbarios6

iOS6 music and clock app tab bar with segmented pressed buttons


Does anyone know how to style their uitabbar like Apple in Music and Clock apps on the iPad?enter image description here

I have been searching the web over but I can't find much out there.

Thanks

Edit:

Rephrasing, I'm trying to understand how to go about setting this up. I've been trying using uitabbarcontroller but I wasn't sure if this was a manipulated style of uitabbaritems or if it was using segmented controls. It seems to be a common view in Apple's new apps, but I wasn't sure how much customization was needed to achieve the effect. If I wanted to have two unique views selectable in a similar fashion to Apple's Music and Clock apps, would I approach as follows:

  • UIViewController (root)
    • UIToolbar
      • Segmented Control
        • Button 1
          • Loads ViewController1
        • Button 2
          • Loads ViewController2

Solution

  • That is a UISegmentedControl. You can style its appearance using the following methods:

    /* Default tintColor is nil. Only used if style is UISegmentedControlStyleBar or UISegmentedControlStyleBezeled
     */
    @property(nonatomic,retain) UIColor *tintColor UI_APPEARANCE_SELECTOR;
    
    /* If backgroundImage is an image returned from -[UIImage resizableImageWithCapInsets:] the cap widths will be calculated from that information, otherwise, the cap width will be calculated by subtracting one from the image's width then dividing by 2. The cap widths will also be used as the margins for text placement. To adjust the margin use the margin adjustment methods.
    
     In general, you should specify a value for the normal state to be used by other states which don't have a custom value set.
    
     Similarly, when a property is dependent on the bar metrics (on the iPhone in landscape orientation, bars have a different height from standard), be sure to specify a value for UIBarMetricsDefault.
     In the case of the segmented control, appearance properties for UIBarMetricsLandscapePhone are only respected for segmented controls in the smaller navigation and toolbars that are used in landscape orientation on the iPhone.
     */
    - (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; 
    - (UIImage *)backgroundImageForState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
    
    /* To customize the segmented control appearance you will need to provide divider images to go between two unselected segments (leftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal), selected on the left and unselected on the right (leftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal), and unselected on the left and selected on the right (leftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected).
     */
    - (void)setDividerImage:(UIImage *)dividerImage forLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
    - (UIImage *)dividerImageForLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState barMetrics:(UIBarMetrics)barMetrics  NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
    
    /* You may specify the font, text color, text shadow color, and text shadow offset for the title in the text attributes dictionary, using the keys found in UIStringDrawing.h.
     */
    - (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
    - (NSDictionary *)titleTextAttributesForState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
    
    /* For adjusting the position of a title or image within the given segment of a segmented control.
     */
    - (void)setContentPositionAdjustment:(UIOffset)adjustment forSegmentType:(UISegmentedControlSegment)leftCenterRightOrAlone barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; 
    - (UIOffset)contentPositionAdjustmentForSegmentType:(UISegmentedControlSegment)leftCenterRightOrAlone barMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
    

    This example sets the background and the divider images for the different selection states (using the appearance proxy to change the appearance of all segmented controls):

    UIImage *segmentSelected = 
        [[UIImage imageNamed:@"segcontrol_sel.png"] 
            resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
    UIImage *segmentUnselected = 
        [[UIImage imageNamed:@"segcontrol_uns.png"] 
            resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
    UIImage *segmentSelectedUnselected = 
        [UIImage imageNamed:@"segcontrol_sel-uns.png"];
    UIImage *segUnselectedSelected = 
        [UIImage imageNamed:@"segcontrol_uns-sel.png"];
    UIImage *segmentUnselectedUnselected = 
        [UIImage imageNamed:@"segcontrol_uns-uns.png"];
    
    [[UISegmentedControl appearance] setBackgroundImage:segmentUnselected 
        forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UISegmentedControl appearance] setBackgroundImage:segmentSelected 
        forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
    
    [[UISegmentedControl appearance] setDividerImage:segmentUnselectedUnselected 
        forLeftSegmentState:UIControlStateNormal 
        rightSegmentState:UIControlStateNormal 
        barMetrics:UIBarMetricsDefault];
    [[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected 
        forLeftSegmentState:UIControlStateSelected 
        rightSegmentState:UIControlStateNormal 
        barMetrics:UIBarMetricsDefault];
    [[UISegmentedControl appearance] 
        setDividerImage:segUnselectedSelected 
        forLeftSegmentState:UIControlStateNormal 
        rightSegmentState:UIControlStateSelected 
        barMetrics:UIBarMetricsDefault];