Skip to content

Commit

Permalink
Merge pull request HeshamMegid#107 from andrewchae/attributed-string
Browse files Browse the repository at this point in the history
Adds ability to use an NSAttributedString directly as title instead of using the block configurator.
  • Loading branch information
HeshamMegid committed Jul 11, 2015
2 parents 92cd025 + cb1e838 commit 1ddc976
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions HMSegmentedControl/HMSegmentedControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,12 @@ - (CGSize)measureTitleAtIndex:(NSUInteger)index {
}

- (NSAttributedString *)attributedTitleAtIndex:(NSUInteger)index {
NSString *title = self.sectionTitles[index];
id title = self.sectionTitles[index];
BOOL selected = (index == self.selectedSegmentIndex) ? YES : NO;

if (!self.titleFormatter) {
if ([title isKindOfClass:[NSAttributedString class]]) {
return (NSAttributedString *)title;
} else if (!self.titleFormatter) {
NSDictionary *titleAttrs = selected ? [self resultingSelectedTitleTextAttributes] : [self resultingTitleTextAttributes];

// the color should be cast to CGColor in order to avoid invalid context on iOS7
Expand Down

0 comments on commit 1ddc976

Please sign in to comment.