AECNCityPickerView 0.0.4

AECNCityPickerView 0.0.4

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最新发布2016 年 10 月

William Wang 维护。




  • William Wang

这是一个易于使用和可定制的视图组件,它展示了带有工具栏、完成按钮、动画、设计选项和数据源的 UIPickerView。它支持 iOS 6,并在 iOS 7 及更高版本中表现更佳,因为它允许您更改 PickerView 的背景颜色。


AECNCityPickerView


安装

手动安装

注意:如果您的项目不使用 ARC:您必须在 Target Settings > Build Phases > Compile Sources 中添加 -fobjc-arc 编译器标志到 AECNCityPickerView.m

  • AECNCityPickerView/AECNCityPickerView 文件夹拖放到您的项目中。
  • 确保您的项目中包含了 CoreGraphics 框架。
  • 通过添加 #import "AECNCityPickerView.h" 来包含 AECNCityPickerView。

用法

(参见 /Demo 目录中的示例 Xcode 项目)

AECNCityPickerView 是以单例的形式创建的(即不需要显式分配和实例化;您可以直接调用 [AECNCityPickerView method])。

显示 PickerView

您可以显示 PickerView

+(void)showPickerViewInView: (UIView *)view
                withDatasource: (id<AECNCityPickerViewDataSource>)dataSource
                withOptions: (NSDictionary *)options
                 completion: (void(^)(AECNLeafRegion *region))completion;

自定义 AECNCityPickerView

两种显示方法都使用一个 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,标注来源将会是一个好主意。