DTFormMenuController 0.1.8

DTFormMenuController 0.1.8

测试测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最新版本2015年3月

Daniel Thengvall 维护。



  • DTHENG

使用方法

  • 首先创建一个新的类,该类扩展 DTFormViewController

ViewController.h 视图文件

#import "DTFormViewController.h"

@interface ViewController : DTFormViewController

@end
  • 然后在实现文件中,您将使用其“对象”初始化表单

ViewController.m 视图文件

- (void)viewDidLoad {
    [super viewDidLoad];

    [super setFormObjects:@[

        // Array of objects that extend DTBaseFormObject

    ]];
}

注意您不需要在 viewDidLoad 方法中执行 setFormObjects,它可以从任何地方调用。

  • 现在,您已经设置好了视图控制器,您需要打开或创建一个 Main.storyboard 文件。
  • 在 Storyboard 中添加一个全新的 UICollectionViewController
  • 找到新的视图控制器 Identity inspectorCustom ClassStoryboard ID 字段设置为 DTFormMenuViewController
  • 现在在视图控制器的 Collection View Flow Layout 中,将 Min Spacing 值设置为 0
  • 在视图控制器中,将 UICollectionViewCellReusable Identifier 设置为 "content"
  • 表单对象是任何扩展 DTBaseFormObject 的类。

ExampleTextInputFormObject.h 视图文件

#import "DTBaseFormObject.h"

@interface ExampleTextInputFormObject : DTBaseFormObject

- (ExampleTextInputFormObject *)initWithPlaceholder:(NSString *)placeholderText onChanged:(void (^)(NSString *text))onChangedBehavior;

@end
  • 在新类的实现中,唯一需要重写的方法是

ExampleTextInputFormObject.m 视图文件

- (UICollectionViewCell *)toCollectionViewCell:(UICollectionView *)collectionView :(NSIndexPath *)indexPath {

    UICollectionViewCell *exampleCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"example" forIndexPath:indexPath];

    // Customize cell

    return exampleCell;
}
  • 在我们可以运行代码之前,我们需要将 ViewController 添加到 Main.storyboard
  • 在 Storyboard 中添加一个全新的 UICollectionViewController
  • 找到新的视图控制器的 Identity inspectorCustom ClassStoryboard ID 字段设置为您类的名称。
  • 现在在视图控制器的 Collection View Flow Layout 中,将 Min Spacing 值设置为 0
  • 在视图控制器中,将 UICollectionViewCellReusable Identifier 设置为 "example"
  • 完成!

安装

DTFormMenuController 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中

pod 'DTFormMenuController', '0.1.8'

没有 Podfile 吗?

您可以将项目轻松更新为使用 CocoaPods

  • 安装 CocoaPods 库
sudo gem install cocoapods
  • 转到您的 .xcodeproj 文件所在的目录
  • 创建一个名为 Podfile 的新文件
  • 更新 Podfile
platform :ios, deployment_target: '8.0'

pod 'DTFormMenuController', '0.1.8'
  • 现在运行此命令
pod install
  • 从现在开始,只在项目中打开 .xcworkspace 文件,而不是 .xcodeproj
  • 完成!

作者

DTHENG, [email protected]

授权

DTFormMenuController遵守MIT授权协议。有关更多信息,请参阅LICENSE文件。