Created
April 9, 2013 10:23
-
-
Save maxhuk/5344679 to your computer and use it in GitHub Desktop.
Fast UISegmentedControl appearance customization.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UISegmentedControl+Background.h | |
// | |
// Created by Maksym Huk on 4/3/13. | |
// Copyright (c) 2013 Maksym Huk. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UISegmentedControl (Background) | |
- (void)setBackgroundImage:(UIImage *)backgroundImage highlightedBackgroundImage:(UIImage *)highlightedBackgroundImage dividerImage:(UIImage *)dividerImage; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UISegmentedControl+Background.m | |
// | |
// Created by Maksym Huk on 4/3/13. | |
// Copyright (c) 2013 Maksym Huk. All rights reserved. | |
// | |
#import "UISegmentedControl+Background.h" | |
@implementation UISegmentedControl (Background) | |
- (void)setBackgroundImage:(UIImage *)backgroundImage highlightedBackgroundImage:(UIImage *)highlightedBackgroundImage dividerImage:(UIImage *)dividerImage | |
{ | |
CGRect frame = self.frame; | |
self.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, backgroundImage.size.height); | |
[self setBackgroundImage:backgroundImage forState:UIControlStateDisabled barMetrics:UIBarMetricsDefault]; | |
[self setBackgroundImage:backgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; | |
[self setBackgroundImage:highlightedBackgroundImage forState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; | |
[self setBackgroundImage:highlightedBackgroundImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault]; | |
[self setDividerImage:dividerImage forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; | |
[self setDividerImage:dividerImage forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; | |
[self setDividerImage:dividerImage forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment