Skip to content

Commit fbe7930

Browse files
committed
tab策略调整,字号调整
1 parent 6f732c8 commit fbe7930

4 files changed

Lines changed: 64 additions & 19 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"scale" : "2x",
10+
"filename" : "tag_list_down@2x.png"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
998 Bytes
Loading

Coding_iOS/Vendor/XTSegmentControl/XTSegmentControl.m

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

Coding_iOS/Views/ProjectTopicsView.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ - (void)openList:(NSInteger)segmentIndex
154154
{
155155
TopicListView *lView = (TopicListView *)[self viewWithTag:9898];
156156
if (!lView) {
157+
// 显示
157158
_segIndex = segmentIndex;
158159
NSArray *lists = (NSArray *)_total[segmentIndex];
159160
CGRect rect = CGRectMake(0, kMySegmentControl_Height, kScreen_Width, self.frame.size.height - kMySegmentControl_Height);
@@ -174,6 +175,7 @@ - (void)openList:(NSInteger)segmentIndex
174175
[self addSubview:listView];
175176
[listView showBtnView];
176177
} else if (_segIndex != segmentIndex) {
178+
// 另展示
177179
_segIndex = segmentIndex;
178180

179181
NSArray *nAry = nil;
@@ -189,6 +191,9 @@ - (void)openList:(NSInteger)segmentIndex
189191
[weakSelf changeIndex:index withSegmentIndex:segmentIndex];
190192
}];
191193
} else {
194+
// 隐藏
195+
[self.mySegmentControl selectIndex:-1];
196+
192197
[lView hideBtnView];
193198
}
194199
}

0 commit comments

Comments
 (0)