这是一个易于使用和可定制的视图组件,它展示了带有工具栏、完成按钮、动画、设计选项和数据源的 UIPickerView
。它支持 iOS 6,并在 iOS 7 及更高版本中表现更佳,因为它允许您更改 PickerView 的背景颜色。
注意:如果您的项目不使用 ARC:您必须在 Target Settings > Build Phases > Compile Sources 中添加 -fobjc-arc
编译器标志到 AECNCityPickerView.m
。
AECNCityPickerView/AECNCityPickerView
文件夹拖放到您的项目中。#import "AECNCityPickerView.h"
来包含 AECNCityPickerView。(参见 /Demo
目录中的示例 Xcode 项目)
AECNCityPickerView 是以单例的形式创建的(即不需要显式分配和实例化;您可以直接调用 [AECNCityPickerView method]
)。
您可以显示 PickerView
+(void)showPickerViewInView: (UIView *)view
withDatasource: (id<AECNCityPickerViewDataSource>)dataSource
withOptions: (NSDictionary *)options
completion: (void(^)(AECNLeafRegion *region))completion;
两种显示方法都使用一个 NSDictionary
来设置 AECNCityPickerView
的选项。如果希望 PickerView 看起来更原生,只需使用 withOptions: nil
。如果需要自定义,可以使用不同的属性来自定义 PickerView。所有属性都是可选的,这意味着如果您只想更改一项,例如文本颜色,可以这样操作,withOptions: @{AECNCityPickerView_textColor: [UIColor redColor]}
选项
AECNCityPickerView_backgroundColor
- UIColor
AECNCityPickerView_textColor
- UIColor
AECNCityPickerView_toolbarBackgroundColor
- UIColor
AECNCityPickerView_toolbarBtnTintColor
- UIColor
AECNCityPickerView_font
- UIFont
AECNCityPickerView_ValueY
- NSInteger
AECNCityPickerView_selectedObject
- id
AECNCityPickerView_toolbarBackgroundImage
- UIImage
AECNCityPickerView_textAlignment
- NSNumber
/*
Options:
AECNCityPickerView_backgroundColor - UIColor - The background color of the PickerView (>=iOS 7)
AECNCityPickerView_textColor - UIColor - The text color of the PickerView
AECNCityPickerView_toolbarBackgroundColor - UIColor - The background color of the toolbar
AECNCityPickerView_toolbarBtnTintColor - UIColor - The background color (<= iOS 6) or text color (>=iOS 7) of the Done button
AECNCityPickerView_font - UIFont - The font of the PickerView labels
AECNCityPickerView_ValueY - NSInteger - The Y value from the top of every label in the PickerView, useful when changing font/font-size.
AECNCityPickerView_selectedObject - id - The selected object presented in the PickerView, an object from the array, for eg. [yourArray objectAtIndex:0];
AECNCityPickerView_toolbarBackgroundImage - UIImage - The background image of the toolbar (320 x 44 for non retina, 640 x 88 for retina)
AECNCityPickerView_textAlignment - NSNumber - The text alignment of the labels in the PickerView, @0 for Left, @1 for Center, @2 for Right
*/
UIFont *customFont = [UIFont fontWithName:@"Palatino-Bold" size:19.0];
NSDictionary *options = @{AECNCityPickerView_backgroundColor: [UIColor blackColor],
AECNCityPickerView_textColor: [UIColor whiteColor],
AECNCityPickerView_toolbarColor: [UIColor darkGrayColor],
AECNCityPickerView_toolbarBtnTintColor: [UIColor whiteColor],
AECNCityPickerView_font: customFont,
AECNCityPickerView_ValueY: @5};
[AECNCityPickerView showPickerViewInView:self.view
withDataSource:self
withOptions:options
completion:^(AECNLeafRegion *region) {
//region is the return value which you can use as you wish
//deal with selected region
}];
AECNCityPickerView是由王威廉开发的。如果您有功能建议或错误报告,请通过发送问题报告或提交Pull请求来帮助。如果您在项目中使用了AECNCityPickerView,标注来源将会是一个好主意。