要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install
HXSegmentButton 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "HXSegmentButton"
//1.Setup SegmentButton
- (HXSegmentButton *)segmentButton {
if (!_segmentButton) {
NSArray *array = @[@"Button0", @"Button1", @"Button2", @"Button3"];
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
//1.1 Setup segment button frame
_segmentButton = [[HXSegmentButton alloc] initWithTitles:array x:0 y:64 width:screenWidth height:36];
//1.2 Setup segment button colors
[_segmentButton setupButtonsNormalColor:[UIColor whiteColor] selectedColor:[UIColor redColor]];
//1.3 Setup segment button background colors and underLine color
[_segmentButton setupBackgroundNormalColor:[UIColor blackColor] selectedColor:[UIColor yellowColor] underLineColor:[UIColor redColor]];
[self.view addSubview:_segmentButton];
}
return _segmentButton;
}
[self.segmentButton initButtonTagWith:0];
//3.1Callback block
__weak typeof(self) weakSelf = self;
[_segmentButton returnHeaderIndex:^(NSUInteger current) {
__strong typeof(weakSelf) strongSelf = weakSelf;
NSLog(@"%ld", current);
//3.2 Receive the button tag
[strongSelf segmentButtonTag:current];
}];
[self.segmentButton setupUnderLineAnimation];
Insofan, [email protected]
HXSegmentButton 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。