HMSegmentedControl源代码解析(12)
- UID
- 1066743
|
HMSegmentedControl源代码解析(12)
/**
返回一个富文本string
@param index index
@return 富文本string
*/
- (NSAttributedString *)attributedTitleAtIndexNSUInteger)index {
id title = self.sectionTitles[index];
BOOL selected = (index == self.selectedSegmentIndex) ? YES : NO;
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
UIColor *titleColor = titleAttrs[NSForegroundColorAttributeName];
if (titleColor) {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:titleAttrs];
dict[NSForegroundColorAttributeName] = (id)titleColor.CGColor;
titleAttrs = [NSDictionary dictionaryWithDictionary:dict];
}
return [[NSAttributedString alloc] initWithStringNSString *)title attributes:titleAttrs];
} else {
return self.titleFormatter(self, title, index, selected);
}
} |
|
|
|
|
|