12
12
13
13
#define XTSegmentControlItemFont (15 )
14
14
15
- #define XTSegmentControlHspace (0 )
15
+ #define XTSegmentControlHspace ([ self p_Hspace ] )
16
16
17
- #define XTSegmentControlLineHeight (2 )
17
+ #define XTSegmentControlLineHeight ([ self p_LineHeight ] )
18
18
19
19
#define XTSegmentControlAnimationTime (0.3 )
20
20
@@ -90,7 +90,8 @@ - (id)initWithFrame:(CGRect)frame title:(NSString *)title type:(XTSegmentControl
90
90
default :
91
91
{
92
92
_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))];
94
95
label.font = [UIFont systemFontOfSize: XTSegmentControlItemFont];
95
96
label.textAlignment = NSTextAlignmentCenter;
96
97
label.text = title;
@@ -99,7 +100,6 @@ - (id)initWithFrame:(CGRect)frame title:(NSString *)title type:(XTSegmentControl
99
100
label;
100
101
});
101
102
102
-
103
103
[self addSubview: _titleLabel];
104
104
}
105
105
break ;
@@ -373,11 +373,12 @@ - (void)addRedLine
373
373
{
374
374
if (!_lineView) {
375
375
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];
381
382
_lineView.backgroundColor = kColorBrandGreen ;
382
383
[_contentView addSubview: _lineView];
383
384
@@ -387,6 +388,24 @@ - (void)addRedLine
387
388
}
388
389
}
389
390
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
+
390
409
- (void )setTitle : (NSString *)title withIndex : (NSInteger )index
391
410
{
392
411
XTSegmentControlItem *curItem = [_items objectAtIndex: index ];
0 commit comments