HTSegmentsView 对一组子控件进行“单选”状态管理,并支持选中状态的切换与动画。
HTSegmentsView *segmentsView = [[HTHorizontalSegmentsView alloc] initWithSelectedIndex:0];
segmentsView.frame = CGRectMake(30,100,260,50);
segmentsView.segmentsDelegate = self;
注意:segmentsView 内部对 datasource 是弱引用,使用者需要保证 datasource 的生命周期。
HTStringToLabelDataSource *dataSource = [[HTStringToLabelDataSource alloc] initWithArray:@[@"button1",@"button2",@"button3"] segmentCellClass:nil];
segmentsView.segmentsDataSource = dataSource;
HTSublineSegmentViewAnimator *animator = [[HTSublineSegmentViewAnimator alloc] initWithSegmentsView:segmentsView backgroundColor:[UIColor lightGrayColor] lineColor:[UIColor greenColor] lineHeight:5];
segmentsView.animator = animator;
HTSegmentsView 继承自 UIScrollView,为了避免 NavigationController 导致的 -64
的 contentOffset 问题,需要将 HTSegmentsView 所在 ViewController 的 automaticallyAdjustsScrollViewInsets 属性设置为 NO,或者在合适的时间将修改掉 HTSegmentsView 的 contentOffset 值。
该项目最低支持 iOS 7.0
和 Xcode 7.0
HTSegmentsView 使用 MIT 许可证,详情见 LICENSE 文件。