@@ -62,7 +62,8 @@ - (id)initWithFrame:(CGRect)frame title:(NSString *)title type:(XTSegmentControl
6262 {
6363 _titleLabel = ({
6464 UILabel *label = [[UILabel alloc ] initWithFrame: CGRectMake (0 , 0 , CGRectGetWidth (self .bounds), CGRectGetHeight (self .bounds))];
65- label.font = [UIFont systemFontOfSize: XTSegmentControlItemFont - 2 ];
65+
66+ label.font = [UIFont systemFontOfSize: (kDevice_Is_iPhone6Plus ) ? (XTSegmentControlItemFont + 1 ) : (kDevice_Is_iPhone6 ? XTSegmentControlItemFont : XTSegmentControlItemFont - 2 )];
6667 label.textAlignment = NSTextAlignmentCenter;
6768 label.text = title;
6869 label.textColor = [UIColor colorWithHexString: @" 0x222222" ];
@@ -120,7 +121,7 @@ - (void)setSelected:(BOOL)selected
120121 [_titleLabel setTextColor: (selected ? [UIColor colorWithHexString: @" 0x3bbd79" ]:[UIColor colorWithHexString: @" 0x222222" ])];
121122 }
122123 if (_titleIconView) {
123- [_titleIconView setImage: [UIImage imageNamed: selected ? @" tag_list_up_s " : @" tag_list_up" ]];
124+ [_titleIconView setImage: [UIImage imageNamed: selected ? @" tag_list_down " : @" tag_list_up" ]];
124125 }
125126 }
126127 break ;
@@ -291,7 +292,7 @@ - (void)initItemsWithTitleArray:(NSArray *)titleArray withIcon:(BOOL)isIcon
291292 NSString *title = titleArray[i];
292293 XTSegmentControlItem *item = [[XTSegmentControlItem alloc ] initWithFrame: rect title: title type: isIcon ?
293294 XTSegmentControlItemTypeTitleAndIcon : XTSegmentControlItemTypeTitle];
294- if (i == 0 ) {
295+ if (!isIcon && i == 0 ) {
295296 [item setSelected: YES ];
296297 }
297298 [_items addObject: item];
@@ -333,6 +334,7 @@ - (void)initItemsWithTitleArray:(NSArray *)titleArray withIcon:(BOOL)isIcon
333334 self.currentIndex = 0 ;
334335 [self selectIndex: 0 ];
335336 if (isIcon) {
337+ [self selectIndex: -1 ];
336338 for (int i=1 ; i<_itemFrames.count ; i++) {
337339 CGRect rect = [_itemFrames[i] CGRectValue ];
338340
@@ -374,21 +376,37 @@ - (void)setTitle:(NSString *)title withIndex:(NSInteger)index
374376- (void )selectIndex : (NSInteger )index
375377{
376378 [self addRedLine ];
377- if (index != _currentIndex) {
378- XTSegmentControlItem *curItem = [_items objectAtIndex: index];
379- CGRect rect = [_itemFrames[index] CGRectValue ];
380- CGRect lineRect = CGRectMake (CGRectGetMinX (rect) + XTSegmentControlHspace, CGRectGetHeight (rect) - XTSegmentControlLineHeight, CGRectGetWidth (rect) - 2 * XTSegmentControlHspace, XTSegmentControlLineHeight);
381- [UIView animateWithDuration: XTSegmentControlAnimationTime animations: ^{
382- _lineView.frame = lineRect;
383- } completion: ^(BOOL finished) {
384- [_items enumerateObjectsUsingBlock: ^(XTSegmentControlItem *item, NSUInteger idx, BOOL *stop) {
385- [item setSelected: NO ];
386- }];
387- [curItem setSelected: YES ];
388- _currentIndex = index;
389- }];
379+ if (index < 0 ) {
380+ _currentIndex = -1 ;
381+ _lineView.hidden = TRUE ;
382+ for (XTSegmentControlItem *curItem in _items) {
383+ [curItem setSelected: NO ];
384+ }
385+ } else {
386+ _lineView.hidden = FALSE ;
387+
388+ if (index != _currentIndex) {
389+ XTSegmentControlItem *curItem = [_items objectAtIndex: index];
390+ CGRect rect = [_itemFrames[index] CGRectValue ];
391+ CGRect lineRect = CGRectMake (CGRectGetMinX (rect) + XTSegmentControlHspace, CGRectGetHeight (rect) - XTSegmentControlLineHeight, CGRectGetWidth (rect) - 2 * XTSegmentControlHspace, XTSegmentControlLineHeight);
392+ if (_currentIndex < 0 ) {
393+ _lineView.frame = lineRect;
394+ [curItem setSelected: YES ];
395+ _currentIndex = index;
396+ } else {
397+ [UIView animateWithDuration: XTSegmentControlAnimationTime animations: ^{
398+ _lineView.frame = lineRect;
399+ } completion: ^(BOOL finished) {
400+ [_items enumerateObjectsUsingBlock: ^(XTSegmentControlItem *item, NSUInteger idx, BOOL *stop) {
401+ [item setSelected: NO ];
402+ }];
403+ [curItem setSelected: YES ];
404+ _currentIndex = index;
405+ }];
406+ }
407+ }
408+ [self setScrollOffset: index];
390409 }
391- [self setScrollOffset: index];
392410}
393411
394412- (void )moveIndexWithProgress : (float )progress
@@ -427,7 +445,7 @@ - (void)moveIndexWithProgress:(float)progress
427445 moveRect.size = CGSizeMake (CGRectGetWidth (origionLineRect) + delta * (CGRectGetWidth (lineRect) - CGRectGetWidth (origionLineRect)), CGRectGetHeight (lineRect));
428446 moveRect.origin = CGPointMake (CGRectGetMidX (origionLineRect) + delta * (CGRectGetMidX (lineRect) - CGRectGetMidX (origionLineRect)) - CGRectGetMidX (moveRect), CGRectGetMidY (origionLineRect) - CGRectGetMidY (moveRect));
429447 _lineView.frame = moveRect;
430- }else if (delta < 0 ){
448+ } else if (delta < 0 ){
431449
432450 if (_currentIndex == 0 ) {
433451 return ;
@@ -444,7 +462,8 @@ - (void)moveIndexWithProgress:(float)progress
444462 }
445463}
446464
447- - (void )setCurrentIndex : (NSInteger )currentIndex {
465+ - (void )setCurrentIndex : (NSInteger )currentIndex
466+ {
448467 currentIndex = MAX (0 , MIN (currentIndex, _items.count ));
449468
450469 if (currentIndex != _currentIndex) {
0 commit comments