Browse files

Merge branch 'UISegmentedControlXIB'

  • Loading branch information...
2 parents e5d933a + 1d3b86f commit e7e0d129863232fb3ff2c058dd62d84e68559930 @jallum jallum committed Aug 1, 2011
Showing with 78 additions and 24 deletions.
  1. +5 −1 UIKit/Classes/UIImageView.m
  2. +6 −2 UIKit/Classes/UISegment.h
  3. +15 −1 UIKit/Classes/UISegment.m
  4. +52 −20 UIKit/Classes/UISegmentedControl.m
View
6 UIKit/Classes/UIImageView.m
@@ -33,6 +33,8 @@
#import "UIColor.h"
#import <QuartzCore/QuartzCore.h>
+static NSString* const kUIImageKey = @"UIImage";
+
static NSArray *CGImagesWithUIImages(NSArray *images)
{
NSMutableArray *CGImages = [NSMutableArray arrayWithCapacity:[images count]];
@@ -71,7 +73,9 @@ - (id)initWithFrame:(CGRect)frame
- (id) initWithCoder:(NSCoder*)coder
{
if (nil != (self = [super initWithCoder:coder])) {
- /* XXX: Implement Me */
+ if ([coder containsValueForKey:kUIImageKey]) {
+ self.image = [coder decodeObjectForKey:kUIImageKey];
+ }
}
return self;
}
View
8 UIKit/Classes/UISegment.h
@@ -1,5 +1,9 @@
#import "UIImageView.h"
-@interface UISegment : UIImageView <NSCoding>
-
+@interface UISegment : UIImageView <NSCoding> {
+ NSString *_title;
+ NSInteger _position;
+}
+@property (nonatomic, copy) NSString *title;
+@property (nonatomic, assign) NSInteger position;
@end
View
16 UIKit/Classes/UISegment.m
@@ -1,11 +1,20 @@
#import "UISegment.h"
+static NSString* const kUISegmentInfoKey = @"UISegmentInfo";
+static NSString* const kUISegmentPositionKey = @"UISegmentPosition";
+
@implementation UISegment
+@synthesize title = _title, position = _position;
- (id) initWithCoder:(NSCoder*)coder
{
if (nil != (self = [super initWithCoder:coder])) {
- /* XXX: Implement Me */
+ if ([coder containsValueForKey:kUISegmentInfoKey]) {
+ self.title = [coder decodeObjectForKey:kUISegmentInfoKey];
+ }
+ if ([coder containsValueForKey:kUISegmentPositionKey]) {
+ self.position = [coder decodeIntegerForKey:kUISegmentPositionKey];
+ }
}
return self;
}
@@ -15,4 +24,9 @@ - (void) encodeWithCoder:(NSCoder*)coder
[self doesNotRecognizeSelector:_cmd];
}
+- (void)dealloc
+{
+ [_title release];
+ [super dealloc];
+}
@end
View
72 UIKit/Classes/UISegmentedControl.m
@@ -14,6 +14,11 @@
#import "UIGraphics.h"
static NSString *kSSSegmentedControlEnabledKey = @"enabled";
+static NSString* const kUISegmentsKey = @"UISegments";
+static NSString* const kUISegmentedControlStyleKey = @"UISegmentedControlStyle";
+static NSString* const kUISegmentedControlTintColorKey = @"UISegmentedControlTintColor";
+static NSString* const kUISelectedSegmentIndexKey = @"UISelectedSegmentIndex";
+static NSString* const kUIMomentaryKey = @"UIMomentary";
@interface UISegmentedControl ()
@property (nonatomic, retain) UIImage *buttonImage;
@@ -27,7 +32,7 @@ @interface UISegmentedControl ()
@property (nonatomic, retain) UIColor *textShadowColor;
@property (nonatomic, assign) CGSize textShadowOffset;
@property (nonatomic, assign) UIEdgeInsets textEdgeInsets;
-
+- (void)_commonInitForUISegmentedControl;
- (NSMutableDictionary *)_metaForSegmentIndex:(NSUInteger)index;
- (id)_metaValueForKey:(NSString *)key segmentIndex:(NSUInteger)index;
- (void)_setMetaValue:(id)value forKey:(NSString *)key segmentIndex:(NSUInteger)index;
@@ -74,7 +79,30 @@ - (void)dealloc
- (id) initWithCoder:(NSCoder*)coder
{
if (nil != (self = [super initWithCoder:coder])) {
- /* XXX: Implement Me */
+ [self _commonInitForUISegmentedControl];
+ if ([coder containsValueForKey:kUISegmentsKey]) {
+ NSArray *segments = [coder decodeObjectForKey:kUISegmentsKey];
+ for (UISegment *segment in segments) {
+ if (segment.image) {
+ [self setImage:segment.image forSegmentAtIndex:segment.position];
+ }
+ if (segment.title) {
+ [self setTitle:segment.title forSegmentAtIndex:segment.position];
+ }
+ }
+ }
+ if ([coder containsValueForKey:kUISegmentedControlStyleKey]) {
+ self.segmentedControlStyle = [coder decodeIntegerForKey:kUISegmentedControlStyleKey];
+ }
+ if ([coder containsValueForKey:kUISegmentedControlTintColorKey]) {
+ self.tintColor = [coder decodeObjectForKey:kUISegmentedControlTintColorKey];
+ }
+ if ([coder containsValueForKey:kUISelectedSegmentIndexKey]) {
+ self.selectedSegmentIndex = [coder decodeIntegerForKey:kUISelectedSegmentIndexKey];
+ }
+ if ([coder containsValueForKey:kUIMomentaryKey]) {
+ self.momentary = [coder decodeBoolForKey:kUIMomentaryKey];
+ }
}
return self;
}
@@ -119,28 +147,32 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
- self.backgroundColor = [UIColor clearColor];
-
- _segments = [[NSMutableArray alloc] init];
- _momentary = NO;
-
- // TODO: add images
- self.buttonImage = [[UIImage imageNamed:@"UISegmentBarButton.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0];
- self.highlightedButtonImage = [[UIImage imageNamed:@"UISegmentBarButtonHighlighted.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0];
- self.dividerImage = [UIImage imageNamed:@"UISegmentBarDivider.png"];
- self.highlightedDividerImage = [UIImage imageNamed:@"UISegmentBarDividerHighlighted.png"];
- self.selectedSegmentIndex = UISegmentedControlNoSegment;
-
- _font = [[UIFont boldSystemFontOfSize:12.0f] retain];
- _textColor = [[UIColor whiteColor] retain];
- _disabledTextColor = [[UIColor colorWithWhite:0.561f alpha:1.0f] retain];
- _textShadowColor = [[UIColor colorWithWhite:0.0f alpha:0.5f] retain];
- _textShadowOffset = CGSizeMake(0.0f, -1.0f);
- _textEdgeInsets = UIEdgeInsetsMake(-1.0f, 0.0f, 0.0f, 0.0f);
+ [self _commonInitForUISegmentedControl];
}
return self;
}
+- (void)_commonInitForUISegmentedControl
+{
+ self.backgroundColor = [UIColor clearColor];
+
+ _segments = [[NSMutableArray alloc] init];
+ _momentary = NO;
+
+ // TODO: add images
+ self.buttonImage = [[UIImage imageNamed:@"UISegmentBarButton.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0];
+ self.highlightedButtonImage = [[UIImage imageNamed:@"UISegmentBarButtonHighlighted.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0];
+ self.dividerImage = [UIImage imageNamed:@"UISegmentBarDivider.png"];
+ self.highlightedDividerImage = [UIImage imageNamed:@"UISegmentBarDividerHighlighted.png"];
+ self.selectedSegmentIndex = UISegmentedControlNoSegment;
+
+ _font = [[UIFont boldSystemFontOfSize:12.0f] retain];
+ _textColor = [[UIColor whiteColor] retain];
+ _disabledTextColor = [[UIColor colorWithWhite:0.561f alpha:1.0f] retain];
+ _textShadowColor = [[UIColor colorWithWhite:0.0f alpha:0.5f] retain];
+ _textShadowOffset = CGSizeMake(0.0f, -1.0f);
+ _textEdgeInsets = UIEdgeInsetsMake(-1.0f, 0.0f, 0.0f, 0.0f);
+}
- (void)drawRect:(CGRect)frame
{

0 comments on commit e7e0d12

Please sign in to comment.