Skip to content

Commit 2ac38f6

Browse files
committed
Fix text measurement for titleFormatter
1 parent 1c9a0fa commit 2ac38f6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

HMSegmentedControl/HMSegmentedControl.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,12 @@ - (void)setSelectionIndicatorBoxOpacity:(CGFloat)selectionIndicatorBoxOpacity
206206
- (CGSize)measureTitleAtIndex:(NSUInteger)idx {
207207
id title = self.sectionTitles[idx];
208208
CGSize size = CGSizeZero;
209-
if ([title isKindOfClass:[NSString class]]) {
210-
NSDictionary *titleAttrs = idx == self.selectedSegmentIndex ? [self resultingSelectedTitleTextAttributes] : [self resultingTitleTextAttributes];
209+
BOOL selected = idx == self.selectedSegmentIndex;
210+
if ([title isKindOfClass:[NSString class]] && self.titleFormatter == nil) {
211+
NSDictionary *titleAttrs = selected ? [self resultingSelectedTitleTextAttributes] : [self resultingTitleTextAttributes];
211212
size = [(NSString *)title sizeWithAttributes:titleAttrs];
213+
} else if ([title isKindOfClass:[NSString class]] && self.titleFormatter != nil) {
214+
size = [self.titleFormatter(self, title, selected) size];
212215
} else if ([title isKindOfClass:[NSAttributedString class]]) {
213216
size = [(NSAttributedString *)title size];
214217
} else {

0 commit comments

Comments
 (0)