DZNSegmentedControl
A drop-in replacement for UISegmentedControl for showing counts, to be used typically on a user profile.
一个UISegmentedControl的子类,用以扩展UISegmentedControl的功能,可以用在展示用户的信息上.
Features
- Customizable control with tint color, font, sizes and animation duration. 可以定制填充颜色,字体,尺寸以及动画的方向
- Animated and width auto-adjusting selection indicator. 可以做动画以及自动适应.
- UIBarPositioning support. 支持UIBarPositioning
- UIAppearance support. 支持UIAppearance
- ARC & 64bits. ARC 以及 64位
Installation
Available in Cocoa Pods
你可以使用Cocoa Pods安装
pod 'DZNSegmentedControl'
How to use
For complete documentation, visit CocoaPods' auto-generated doc
你可以参考文档 visit CocoaPods' auto-generated doc
Step 1
Import "DZNSegmentedControl.h"
导入头文件
Step 2
Creating a new instance of DZNSegmentedControl is very similar to what you would do with UISegmentedControl:
创建出 DZNSegmentedControl 对象,与创建 UISegmentedControl 类似:
NSArray *items = @[@"Tweets", @"Following", @"Followers"];
DZNSegmentedControl *control = [[DZNSegmentedControl alloc] initWithItems:items];
control.tintColor = [UIColor blueColor];
control.delegate = self;
control.selectedSegmentIndex = 1;
[control addTarget:self action:@selector(selectedSegment:) forControlEvents:UIControlEventValueChanged];
You can additionally set more properties:
你还可以设置额外的一些属性:
[control setCount:@(12) forSegmentAtIndex:0];
[control setTitle:@"Hello" forSegmentAtIndex:1];
[control setEnabled:NO forSegmentAtIndex:2];
Sample project
Take a look into the sample project. Everything is there.
你也可以参考一下示例项目.