From 54a4a7dcb036a4be53286cbe8167cba203dad9ca Mon Sep 17 00:00:00 2001 From: Priyanka Chhetri Date: Sun, 13 Apr 2014 14:51:32 +0100 Subject: [PATCH 1/3] Enable labels --- RNFrostedSidebar.h | 1 + RNFrostedSidebar.m | 58 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/RNFrostedSidebar.h b/RNFrostedSidebar.h index 566682b..930a940 100644 --- a/RNFrostedSidebar.h +++ b/RNFrostedSidebar.h @@ -67,6 +67,7 @@ @property (nonatomic, weak) id delegate; - (instancetype)initWithImages:(NSArray *)images selectedIndices:(NSIndexSet *)selectedIndices borderColors:(NSArray *)colors; +- (instancetype)initWithImages:(NSArray *)images menuTexts:(NSArray *) menuTexts selectedIndices:(NSIndexSet *)selectedIndices borderColors:(NSArray *)colors; - (instancetype)initWithImages:(NSArray *)images selectedIndices:(NSIndexSet *)selectedIndices; - (instancetype)initWithImages:(NSArray *)images; diff --git a/RNFrostedSidebar.m b/RNFrostedSidebar.m index 6f518c2..b38209d 100644 --- a/RNFrostedSidebar.m +++ b/RNFrostedSidebar.m @@ -175,7 +175,7 @@ @interface RNCalloutItemView : UIView @property (nonatomic, strong) UIImageView *imageView; @property (nonatomic, assign) NSInteger itemIndex; @property (nonatomic, strong) UIColor *originalBackgroundColor; - +@property (nonatomic, strong) UILabel *itemLabel; @end @implementation RNCalloutItemView @@ -185,6 +185,11 @@ - (instancetype)init { _imageView = [[UIImageView alloc] init]; _imageView.backgroundColor = [UIColor clearColor]; _imageView.contentMode = UIViewContentModeScaleAspectFit; + _itemLabel=[[UILabel alloc] init]; + _itemLabel.textAlignment=NSTextAlignmentCenter; + _itemLabel.textColor=[UIColor whiteColor]; + _itemLabel.font=[UIFont fontWithName:@"HelveticaNeue-UltraLight" size:15]; + [self addSubview:_imageView]; } return self; @@ -254,6 +259,56 @@ @implementation RNFrostedSidebar + (instancetype)visibleSidebar { return rn_frostedMenu; } +- (instancetype)initWithImages:(NSArray *)images menuTexts:(NSArray *) menuTexts selectedIndices:(NSIndexSet *)selectedIndices borderColors:(NSArray *)colors { + if (self = [super init]) { + _isSingleSelect = NO; + _contentView = [[UIScrollView alloc] init]; + _contentView.alwaysBounceHorizontal = NO; + _contentView.alwaysBounceVertical = YES; + _contentView.bounces = YES; + _contentView.clipsToBounds = NO; + _contentView.showsHorizontalScrollIndicator = NO; + _contentView.showsVerticalScrollIndicator = NO; + + _width = 150; + _animationDuration = 0.25f; + _itemSize = CGSizeMake(_width/2, _width/2); + _itemViews = [NSMutableArray array]; + _tintColor = [UIColor colorWithWhite:0.2 alpha:0.73]; + _borderWidth = 2; + _itemBackgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.25]; + + if (colors) { + NSAssert([colors count] == [images count], @"Border color count must match images count. If you want a blank border, use [UIColor clearColor]."); + } + + _selectedIndices = [selectedIndices mutableCopy] ?: [NSMutableIndexSet indexSet]; + _borderColors = colors; + _images = images; + + [_images enumerateObjectsUsingBlock:^(UIImage *image, NSUInteger idx, BOOL *stop) { + RNCalloutItemView *view = [[RNCalloutItemView alloc] init]; + view.itemIndex = idx; + view.clipsToBounds = YES; + view.imageView.image = image; + view.itemLabel.text=menuTexts[idx]; + [_contentView addSubview:view]; + + [_contentView addSubview:view.itemLabel]; + + [_itemViews addObject:view]; + + if (_borderColors && _selectedIndices && [_selectedIndices containsIndex:idx]) { + UIColor *color = _borderColors[idx]; + view.layer.borderColor = color.CGColor; + } + else { + view.layer.borderColor = [UIColor clearColor].CGColor; + } + }]; + } + return self; +} - (instancetype)initWithImages:(NSArray *)images selectedIndices:(NSIndexSet *)selectedIndices borderColors:(NSArray *)colors { if (self = [super init]) { @@ -621,6 +676,7 @@ - (void)layoutItems { CGRect frame = CGRectMake(leftPadding, topPadding*idx + self.itemSize.height*idx + topPadding, self.itemSize.width, self.itemSize.height); view.frame = frame; view.layer.cornerRadius = frame.size.width/2.f; + view.itemLabel.frame=CGRectMake(leftPadding, topPadding*idx + self.itemSize.height*idx + topPadding+74, self.itemSize.width, 20); }]; NSInteger items = [self.itemViews count]; From 0bf072b923d7bc98b6ac2181f48b94e7d07ebccd Mon Sep 17 00:00:00 2001 From: Balpreet Patil Date: Sat, 21 Jun 2014 10:42:34 +0100 Subject: [PATCH 2/3] use different font --- RNFrostedSidebar.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RNFrostedSidebar.m b/RNFrostedSidebar.m index b38209d..5c93df2 100644 --- a/RNFrostedSidebar.m +++ b/RNFrostedSidebar.m @@ -188,7 +188,7 @@ - (instancetype)init { _itemLabel=[[UILabel alloc] init]; _itemLabel.textAlignment=NSTextAlignmentCenter; _itemLabel.textColor=[UIColor whiteColor]; - _itemLabel.font=[UIFont fontWithName:@"HelveticaNeue-UltraLight" size:15]; + _itemLabel.font=[UIFont fontWithName:@"HelveticaNeue" size:15]; [self addSubview:_imageView]; } From 7f5fe56a5bf496cdbe9de54e8ea20d3e552a2512 Mon Sep 17 00:00:00 2001 From: Balpreet Patil Date: Sat, 21 Jun 2014 11:01:46 +0100 Subject: [PATCH 3/3] Specify your menu text font --- RNFrostedSidebar.h | 2 +- RNFrostedSidebar.m | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/RNFrostedSidebar.h b/RNFrostedSidebar.h index 930a940..d17b6f6 100644 --- a/RNFrostedSidebar.h +++ b/RNFrostedSidebar.h @@ -67,7 +67,7 @@ @property (nonatomic, weak) id delegate; - (instancetype)initWithImages:(NSArray *)images selectedIndices:(NSIndexSet *)selectedIndices borderColors:(NSArray *)colors; -- (instancetype)initWithImages:(NSArray *)images menuTexts:(NSArray *) menuTexts selectedIndices:(NSIndexSet *)selectedIndices borderColors:(NSArray *)colors; +- (instancetype)initWithImages:(NSArray *)images menuTexts:(NSArray *) menuTexts menuTextFont:(UIFont *) font selectedIndices:(NSIndexSet *)selectedIndices borderColors:(NSArray *)colors; - (instancetype)initWithImages:(NSArray *)images selectedIndices:(NSIndexSet *)selectedIndices; - (instancetype)initWithImages:(NSArray *)images; diff --git a/RNFrostedSidebar.m b/RNFrostedSidebar.m index 5c93df2..b67fb17 100644 --- a/RNFrostedSidebar.m +++ b/RNFrostedSidebar.m @@ -188,7 +188,7 @@ - (instancetype)init { _itemLabel=[[UILabel alloc] init]; _itemLabel.textAlignment=NSTextAlignmentCenter; _itemLabel.textColor=[UIColor whiteColor]; - _itemLabel.font=[UIFont fontWithName:@"HelveticaNeue" size:15]; + _itemLabel.font=[UIFont fontWithName:@"HelveticaNeue" size:15]; [self addSubview:_imageView]; } @@ -259,7 +259,7 @@ @implementation RNFrostedSidebar + (instancetype)visibleSidebar { return rn_frostedMenu; } -- (instancetype)initWithImages:(NSArray *)images menuTexts:(NSArray *) menuTexts selectedIndices:(NSIndexSet *)selectedIndices borderColors:(NSArray *)colors { +- (instancetype)initWithImages:(NSArray *)images menuTexts:(NSArray *) menuTexts menuTextFont:(UIFont *) font selectedIndices:(NSIndexSet *)selectedIndices borderColors:(NSArray *)colors { if (self = [super init]) { _isSingleSelect = NO; _contentView = [[UIScrollView alloc] init]; @@ -292,6 +292,7 @@ - (instancetype)initWithImages:(NSArray *)images menuTexts:(NSArray *) menuTexts view.clipsToBounds = YES; view.imageView.image = image; view.itemLabel.text=menuTexts[idx]; + view.itemLabel.font=font; [_contentView addSubview:view]; [_contentView addSubview:view.itemLabel];