测试已测试 | ✓ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
Released最后发布 | 2016年12月 |
由 Alexey Zankevich,Dmytro Zavgorodniy 维护。
Tipsi DropDown 组件。Tipsi DropDown 组件的核心是 MKDropdownMenu。我们使用我们的分支 TPSMKDropdownMenu,但特别感谢 maxkonovalov 为其组件所做的工作。
要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install
。
请参阅示例 Xcode 工作空间。
创建 TPSDropDown
实例,并将其作为子视图添加到您的视图中。将 delegate
属性设置为实现 TPSDropDownDelegate
协议的视图控制器。
TPSDropDown *dropDown = [[TPSDropDown alloc] initWithFrame:CGRectMake(0.f, 64.f, 320.f, 44.f)];
dropDown.items = @[@"One", @"Two", @"Three"];
dropDown.selectedItemIndex = 0;
dropDown.delegate = self;
[self.view addSubview:dropDown];
您可以将任何符合 TPSDropDownItem
协议的对象的数组设置为 items
属性,这些对象将在下拉菜单中显示。当您设置新项时,您应该自己更新 selectedItemIndex
。
顺便说一句,您也可以设置任何对象的数组,即使这些对象不符合 TPSDropDownItem
协议,在这种情况下,我们不会在下拉菜单中为这些对象显示标题。
@protocol TPSDropDownItem <NSObject>
@required
/// Title, which will show in dropdown.
- (NSString *)title;
@end
我们提供了为 NSString
实现了 TPSDropDownItem
协议的分类。
我们还提供了两个具有我们默认外观的子类。您可以看到 TPSRoundDropDown
和 TPSSquareDropDown
。
您也可以在 Interface Builder 中设置 TPSDropDown
。
UIView
并将其类设置为 TPSDropDown
。delegate
输出口连接到您的视图控制器。/// The corner radius of the dropdown.
/// Default = 0.f.
@property (nonatomic, assign) CGFloat cornerRadius;
/// The border around the dropdown.
/// Default = 0.f.
@property (nonatomic, assign) CGFloat borderWidth;
/// The border around the dropdown.
/// Default = [UIColor clearColor].
@property (nonatomic, strong) UIColor *borderColor;
/// The height of the dropdown rows separators (horizontal lines).
/// Default = 1.f.
@property (nonatomic, assign) CGFloat separatorWidth;
/// The color of the dropdown rows separators (horizontal lines).
/// Default = [UIColor lightGrayColor].
@property (nonatomic, strong) UIColor *separatorColor;
/// The accessory image in the header components, rotates to indicate open/closed state. Provide an image with `UIImageRenderingModeAlwaysTemplate` to respect the view's tint color.
/// Default = nil.
@property (nonatomic, strong) UIImage *indicatorImage;
/// The rotation angle (in radians) of the disclosure indicator when the component is selected.
/// Default = 0.f.
@property (nonatomic, assign) CGFloat indicatorImageSelectionRotation;
/// The font of the label for selected item.
/// The font of the labels in rows.
/// Default = [UIFont systemFontOfSize:[UIFont systemFontSize]].
@property (nonatomic, strong) UIFont *font;
/// The alignment of the label for selected item.
/// The alignment of the labels in rows.
/// Default = NSTextAlignmentLeft.
@property (nonatomic, assign) NSTextAlignment textAlignment;
/// The text color of the label for selected item.
/// The text color of the labels in rows.
/// Default = [UIColor blackColor].
@property (nonatomic, strong) UIColor *textColor;
/// Show a shadow under the dropdown.
/// Default = NO.
@property (nonatomic, assign) BOOL showShadow;
Tipsi 团队
TPSDropDown
可在 MIT 许可证下获得。有关更多信息,请参阅 LICENSE 文件。