1212
1313#define XTSegmentControlItemFont (15 )
1414
15- #define XTSegmentControlHspace (0 )
15+ #define XTSegmentControlHspace ([ self p_Hspace ] )
1616
17- #define XTSegmentControlLineHeight (2 )
17+ #define XTSegmentControlLineHeight ([ self p_LineHeight ] )
1818
1919#define XTSegmentControlAnimationTime (0.3 )
2020
@@ -90,7 +90,8 @@ - (id)initWithFrame:(CGRect)frame title:(NSString *)title type:(XTSegmentControl
9090 default :
9191 {
9292 _titleLabel = ({
93- UILabel *label = [[UILabel alloc ] initWithFrame: CGRectMake (XTSegmentControlHspace, 0 , CGRectGetWidth (self .bounds) - 2 * XTSegmentControlHspace, CGRectGetHeight (self .bounds))];
93+ // UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(XTSegmentControlHspace, 0, CGRectGetWidth(self.bounds) - 2 * XTSegmentControlHspace, CGRectGetHeight(self.bounds))];
94+ UILabel *label = [[UILabel alloc ] initWithFrame: CGRectMake (0 , 0 , CGRectGetWidth (self .bounds), CGRectGetHeight (self .bounds))];
9495 label.font = [UIFont systemFontOfSize: XTSegmentControlItemFont];
9596 label.textAlignment = NSTextAlignmentCenter;
9697 label.text = title;
@@ -99,7 +100,6 @@ - (id)initWithFrame:(CGRect)frame title:(NSString *)title type:(XTSegmentControl
99100 label;
100101 });
101102
102-
103103 [self addSubview: _titleLabel];
104104 }
105105 break ;
@@ -373,11 +373,12 @@ - (void)addRedLine
373373{
374374 if (!_lineView) {
375375 CGRect rect = [_itemFrames[0 ] CGRectValue ];
376- _lineView = [[UIView alloc ] initWithFrame: CGRectMake (
377- CGRectGetMinX (rect),
378- CGRectGetHeight (rect) - XTSegmentControlLineHeight,
379- CGRectGetWidth (rect) - 2 * XTSegmentControlHspace,
380- XTSegmentControlLineHeight)];
376+
377+ CGRect lineRect = CGRectMake (CGRectGetMinX (rect) + XTSegmentControlHspace,
378+ CGRectGetHeight (rect) - XTSegmentControlLineHeight,
379+ CGRectGetWidth (rect) - 2 * XTSegmentControlHspace,
380+ XTSegmentControlLineHeight);
381+ _lineView = [[UIView alloc ] initWithFrame: lineRect];
381382 _lineView.backgroundColor = kColorBrandGreen ;
382383 [_contentView addSubview: _lineView];
383384
@@ -387,6 +388,24 @@ - (void)addRedLine
387388 }
388389}
389390
391+ - (CGFloat)p_Hspace {
392+ CGFloat value = 0 ;
393+ XTSegmentControlItem *item = _items.firstObject ;
394+ if (item.type == XTSegmentControlItemTypeIconUrl) {
395+ value = 15 ;
396+ }
397+ return value;
398+ }
399+
400+ - (CGFloat)p_LineHeight {
401+ CGFloat value = 2 ;
402+ XTSegmentControlItem *item = _items.firstObject ;
403+ if (item.type == XTSegmentControlItemTypeIconUrl) {
404+ value = 2 ;
405+ }
406+ return value;
407+ }
408+
390409- (void )setTitle : (NSString *)title withIndex : (NSInteger )index
391410{
392411 XTSegmentControlItem *curItem = [_items objectAtIndex: index];
0 commit comments