XpdButtons 是一个库,可以动态生成一个视图,其中多个按钮根据按钮标题长度合理排列。一页视图中的行数必须固定,如果按钮更多,它将会显示在下一页视图中。
XpdButtonContainer
创建了一个控制器,您可以在此设置按钮属性和外观。然后您可以获取一个包含按钮合理排列的 UIView
。
buttonproperties 是一个数组,包含按钮信息和标题的字典。在您的 .h
文件中 #import<XpdButtons/XpdButtonContainer.h>
XpdButtonContainer *buttonPageController = [[XpdButtonContainer alloc] init];
// self <--- in which viewContoller you gonna use the view.
buttonPageController.delegate = self;
buttonPageController.buttonProperties = buttonproperties; // NSArray
// Set your other properties for buttons.
buttonPageController.numberOfMaxRow = 3; // Default is 2
UIView *buttonView = [buttonPageController getXpdButtonsViewForParentViewController:self];
XpdButtonAction
是检测按钮点击的 @protocol。实现以下方法以知道何时按钮被点击。 - (void) buttonGetClicked:(XpdButton *)button;
buttonProperties
包含两个键的字典数组。
title
正标题将来展示在按钮标题上。buttonInfo
是一个字典。提示:在以下代理方法中,buttonInfo 对按钮点击将很有用。
- (void) buttonGetClicked:(XpdButton *)button;
NSArray *properties = @[
@{
@"title" : @"button 1",
@"buttonInfo" : @{@"key" : @"value"}
},
@{
@"title" : @"button 2",
@"buttonInfo" : @{@"key" : @"value"}
}];
- (void) buttonGetClicked:(XpdButton *)button {
if ([[button.buttonInfo objectForKey:@"somekey"] isEqualToString:@"somevalue"]) {
// Do something
}
if ([button.title isEqualToString:@"Button 1"]) {
// Do something
}
}
numberOfMaxRow
一页视图中应有多少最大行数。 默认最大行数为 2
buttonBorderColor
设置按钮边框颜色。 默认是黑色。
buttonTitleColor
设置按钮标题颜色。 默认是黑色。
buttonHighlightedTitleColor
设置按钮标题在突出显示状态下的颜色。 默认为红色。
pageIndicatorTintColor
设置页面指示器着色颜色。 默认为浅灰色。
currentPageIndicatorTintColor
设置当前页面指示器着色颜色。 默认为黑色。
-(UIView *) getXpdButtonsViewForParentViewController:(UIViewController *)parent;
返回一个视图,该视图包含在 buttonProperties 中设置的按钮
要运行示例项目,请首先克隆仓库,然后从 Example 目录运行 pod install
XpdButtons 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "XpdButtons"
你想要帮助使其更好、更容易使用。向我发送 pull requestdevelopment
分支上发送 pull request。
Ravi Prakash, [email protected]
XpdButtons 适用于 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。