测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2016 年 4 月 |
由 Andrii Selivanov、Andrii Selivanov 维护。
请查看我们博客上的这篇文章:链接
LUNSegmentedControl 是一个控制,它允许开发者使用自定义外观、可定制的交互动画和其他漂亮的事情(如渐变状态和阴影)使用分段控制。
LUNSegmentedControl 需要 ARC。
要在您的应用程序中使用 LUNSegmentedControl,请将 LUNSegmentedControl 文件夹拖放到您的项目中。
或者您可以使用 CocoaPods
pod 'LUNSegmentedControl'
添加一个 UIView 并将其类更改为 LUNSegmentedControl。然后您需要设置其数据源(无论是通过 storyboard 还是程序化)。实现返回段数的数据源方法
- (NSInteger)numberOfStatesInSegmentedControl:(LUNSegmentedControl *)segmentedControl;
现在实现数据源的一个方法,这样您可以为每个段设置字符串、属性字符串或要显示的视图。
- (NSString *)segmentedControl:(LUNSegmentedControl *)segmentedControl titleForStateAtIndex:(NSInteger)index;
- (NSAttributedString *)segmentedControl:(LUNSegmentedControl *)segmentedControl attributedTitleForStateAtIndex:(NSInteger)index;
- (UIView *)segmentedControl:(LUNSegmentedControl *)segmentedControl viewForStateAtIndex:(NSInteger)index;
如果有必要,您可以使用以下数据源方法设置每个段选中状态下的字符串、属性字符串或视图
- (NSString *)segmentedControl:(LUNSegmentedControl *)segmentedControl titleForSelectedStateAtIndex:(NSInteger)index;
- (NSAttributedString *)segmentedControl:(LUNSegmentedControl *)segmentedControl attributedTitleForSelectedStateAtIndex:(NSInteger)index;
- (UIView *)segmentedControl:(LUNSegmentedControl *)segmentedControl viewForSelectedStateAtIndex:(NSInteger)index;
然后您可以设置以下参数(无论是通过 storyboard 还是程序化),以更改控件的外观
@property (nonatomic, assign) IBInspectable CGFloat cornerRadius;
如果您想自定义控件的圆角半径。
@property (nonatomic, strong) IBInspectable UIColor *textColor;
如果您想自定义未选择段标题的文字颜色。
@property (nonatomic, strong) IBInspectable UIColor *selectedStateTextColor;
用于更改选中段标题的文字颜色。
@property (nonatomic, strong) IBInspectable UIColor *selectorViewColor;
这就是更改选中颜色的方法。
此外,您可以使用以下数据源方法为每个段设置颜色(或多个颜色以获取渐变)以及左侧和右侧的反弹
- (NSArray <UIColor *> *)segmentedControl:(LUNSegmentedControl *)segmentedControl gradientColorsForStateAtIndex:(NSInteger)index;
- (NSArray <UIColor *> *)segmentedControl:(LUNSegmentedControl *)segmentedControl gradientColorsForBounce:(LUNSegmentedControlBounce)bounce;
如果您想接收位置更改的通知,设置控件的代理。
请查看文档以了解更多方法和使用属性。
使用受 MIT 许可证 授权。