HMSegmentedControl 是 UISegmentedControl 的替代品,模仿了 Google Currents 使用的效果。
self.titleSegment = [[HMSegmentedControl alloc]initWithSectionTitles:@[@"title 1",@"title 2"]];
_titleSegment.frame = self.view.bounds;
_titleSegment.selectedSegmentIndex = 0;
_titleSegment.type = HMSegmentedControlTypeText;//风格样式
_titleSegment.font = [UIFont systemFontOfSize:17];
_titleSegment.selectionStyle =HMSegmentedControlSelectionStyleFullWidthStripe; // 选中样式
_titleSegment.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationNone;
_titleSegment.textColor = [UIColor colorWithHex:@"a5b1c1"];
_titleSegment.selectedTextColor = [UIColor colorWithHex:@"0064ab"];
_titleSegment.selectionIndicatorColor = [UIColor clearColor];
_titleSegment.backgroundColor = [UIColor clearColor];
// 添加点击事件
[_titleSegment setIndexChangeBlock:^(NSInteger index) {
NSLog(@"用户切换index == %d",(int)index);
switch (index) {
case 0:
// 第一个按钮
break;
case 1:
// 第二个按钮
break;
default:
break;
}
}];
[self.view addSubview:_titleSegment];
ps: segment选项中间的竖线 需要手动添加