Skip to content

Commit

Permalink
Added separator color getters/setters and considering it on drawRect …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
kalimanborges committed Jun 17, 2015
1 parent 0b1e4f1 commit 74d0515
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
4 changes: 4 additions & 0 deletions Classes/ButtonItemsExampleController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ - (void)viewDidLoad
RKTabItem *twitter = [RKTabItem createButtonItemWithImage:[UIImage imageNamed:@"flickr"] target:self selector:@selector(buttonTabPressed:)];

self.tabViewSocial.horizontalInsets = HorizontalEdgeInsetsMake(70, 70);

self.tabViewSocial.drawSeparators = YES;
self.tabViewSocial.upperSeparatorLineColor = [UIColor colorWithWhite:0.0 alpha:0.2f];
self.tabViewSocial.lowerSeparatorLineColor = [UIColor colorWithWhite:0.5 alpha:0.6f];

[self.tabViewSocial setTabItems:@[tabItemGooglePlus, facebook, flickr, twitter]];
}

Expand Down
2 changes: 2 additions & 0 deletions RKTabView/RKTabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ static inline HorizontalEdgeInsets HorizontalEdgeInsetsMake (CGFloat left, CGFlo
@property (nonatomic, assign) IBOutlet id<RKTabViewDelegate> delegate;
@property (readwrite) BOOL darkensBackgroundForEnabledTabs;
@property (readwrite) BOOL drawSeparators;
@property (nonatomic, strong) UIColor *lowerSeparatorLineColor;
@property (nonatomic, strong) UIColor *upperSeparatorLineColor;
@property (nonatomic, strong) UIColor *enabledTabBackgrondColor;
@property (nonatomic, strong) UIFont *titlesFont;
@property (nonatomic, strong) UIColor *titlesFontColor;
Expand Down
57 changes: 35 additions & 22 deletions RKTabView/RKTabView.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ - (UIColor *)titlesFontColor {
return _titlesFontColor;
}

- (UIColor *)lowerSeparatorLineColor {
if (!_lowerSeparatorLineColor) {
_lowerSeparatorLineColor = [UIColor colorWithWhite:0.5 alpha:0.4f];
}
return _lowerSeparatorLineColor;
}

- (UIColor *)upperSeparatorLineColor {
if (!_upperSeparatorLineColor) {
_upperSeparatorLineColor = [UIColor colorWithWhite:0.0 alpha:0.4f];
}
return _upperSeparatorLineColor;
}

#pragma mark - Private

- (void)cleanTabView {
Expand Down Expand Up @@ -349,33 +363,32 @@ - (void)drawRect:(CGRect)rect {
[self buildUI];

self.clipsToBounds = NO;
if (self.drawSeparators) {

CGFloat darkLineWidth = 0.5f;
CGFloat lightLineWidth = 0.5f;
if (self.drawSeparators &&
self.upperSeparatorLineColor &&
self.lowerSeparatorLineColor) {

UIColor *darkLineColor = [UIColor colorWithWhite:0.0f alpha:0.4f];
UIColor *lightLineColor = [UIColor colorWithWhite:0.5 alpha:0.4f];
CGFloat upperLineWidth = 0.5f;
CGFloat lowerLineWidth = 0.5f;

[self draWLineFromPoint:CGPointMake(0, darkLineWidth/2)
toPoint:CGPointMake(self.bounds.size.width, darkLineWidth/2)
withColor:darkLineColor
width:darkLineWidth];
[self draWLineFromPoint:CGPointMake(0, upperLineWidth/2)
toPoint:CGPointMake(self.bounds.size.width, upperLineWidth/2)
withColor:_upperSeparatorLineColor
width:upperLineWidth];

[self draWLineFromPoint:CGPointMake(0, darkLineWidth + lightLineWidth/2)
toPoint:CGPointMake(self.bounds.size.width, darkLineWidth + lightLineWidth/2)
withColor:lightLineColor
width:lightLineWidth];
[self draWLineFromPoint:CGPointMake(0, upperLineWidth + lowerLineWidth/2)
toPoint:CGPointMake(self.bounds.size.width, upperLineWidth + lowerLineWidth/2)
withColor:_lowerSeparatorLineColor
width:lowerLineWidth];

[self draWLineFromPoint:CGPointMake(0, self.bounds.size.height - darkLineWidth/2 - lightLineWidth)
toPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height - darkLineWidth/2 - lightLineWidth)
withColor:darkLineColor
width:darkLineWidth];
[self draWLineFromPoint:CGPointMake(0, self.bounds.size.height - upperLineWidth/2 - lowerLineWidth)
toPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height - upperLineWidth/2 - lowerLineWidth)
withColor:_upperSeparatorLineColor
width:upperLineWidth];

[self draWLineFromPoint:CGPointMake(0, self.bounds.size.height - lightLineWidth/2)
toPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height - lightLineWidth/2)
withColor:lightLineColor
width:lightLineWidth];
[self draWLineFromPoint:CGPointMake(0, self.bounds.size.height - lowerLineWidth/2)
toPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height - lowerLineWidth/2)
withColor:_lowerSeparatorLineColor
width:lowerLineWidth];
}
}

Expand Down

0 comments on commit 74d0515

Please sign in to comment.