From 561d4121a9a04d7246b6d26a18f5628457f1e602 Mon Sep 17 00:00:00 2001 From: iDay Date: Wed, 8 Jan 2014 12:50:11 +0800 Subject: [PATCH 1/2] if tintColor is white, then set selectedColor to darkTextColor --- UI7Kit/UI7SegmentedControl.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/UI7Kit/UI7SegmentedControl.m b/UI7Kit/UI7SegmentedControl.m index 73038ca..2cb3692 100644 --- a/UI7Kit/UI7SegmentedControl.m +++ b/UI7Kit/UI7SegmentedControl.m @@ -113,7 +113,11 @@ - (void)_backgroundColorUpdated { if ([self titleTextAttributesForState:UIControlStateSelected]) { //if i customize a new style, no need to update this. return; } - NSDictionary *selectedAttributes = @{UITextAttributeTextColor: self.stackedBackgroundColor}; +// NSDictionary *selectedAttributes = @{UITextAttributeTextColor: self.stackedBackgroundColor}; + UIColor *tintColor = self.tintColor; + UIColor *whiteColor = [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f]; + NSDictionary *selectedAttributes = @{UITextAttributeTextColor: [tintColor isEqual:whiteColor] ? [UIColor darkTextColor] : self.stackedBackgroundColor};//if tintColor is white, then set selectedColor to darkTextColor + [self setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected]; } From 66bfcd27a57909c3a6b067329bb37cbd71967b35 Mon Sep 17 00:00:00 2001 From: iDay Date: Thu, 9 Jan 2014 00:06:50 +0800 Subject: [PATCH 2/2] use setter dividerImage --- UI7Kit/UI7SegmentedControl.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/UI7Kit/UI7SegmentedControl.m b/UI7Kit/UI7SegmentedControl.m index 2cb3692..7b2b3e3 100644 --- a/UI7Kit/UI7SegmentedControl.m +++ b/UI7Kit/UI7SegmentedControl.m @@ -104,7 +104,9 @@ - (void)_tintColorUpdated { [self setBackgroundImage:highlightedBackgroundImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault]; [self setBackgroundImage:selectedBackgroundImage forState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; - [self setDividerImage:tintColor.image forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; + if (tintColor != [UIColor clearColor]) {//use setted dividerImage + [self setDividerImage:tintColor.image forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; + } self.layer.borderColor = tintColor.CGColor; }