JSON驅動的iOS表單:Form

jopen 9年前發布 | 17K 次閱讀 Form iOS開發 移動開發

最靈活和強大的方式來在iOS上構建一個表單。

Form源于有一個需求,需要一個表單在iOS app和網頁客戶端之間能共享邏輯,發現JSON是完成這項目的最佳方式。

Form包含了以下特性:

  • 多個分組: For example you can have a group for personal details and another one for shipping information
  • 表單驗證: We supportrequired,maximum length,minimum lengthandformat(regex). We also support many field types, for example:text,number,phone_number,email,date,nameand more
  • 自定義大小: Totalwidthis handled as 100% whileheightis handled in chunks of 85 px
  • 自定義表單項: You can register your custom fields, it's pretty simple (our basic example includes how to make animagefield)
  • 公式或計算的值: We support fields that contain generated values from other fields
  • Targets:Hide,show,update,enable,disableorcleara field using a target. It's pretty powerful, you can even set a condition for your target to run
  • Dropdowns: Generating dropdowns is as easy as adding values to your field, values supportdefaultflags, targets (in case you want to trigger hiding a field based on a selection), string values or numeric values and subtitles (in case you want to hint the consequences of your selection)

用法

基本Form

This are the required steps to create a basic form with a first name field.

JSON驅動的iOS表單:Form

JSON

[
  {
    "id":"group-id",
    "title":"Group title",
    "sections":[
      {
        "id":"section-0",
        "fields":[
          {
            "id":"first_name",
            "title":"First name",
            "type":"name",
            "size":{
              "width":30,
              "height":1
            }
          }
        ]
      }
    ]
  }
]

In your iPad app

// AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Don't forget to set your style, or use the default one if you want
    [FORMDefaultStyle applyStyle];

    //...
}

// UICollectionViewController subclass
- (FORMDataSource *)dataSource
{
    if (_dataSource) return _dataSource;

    _dataSource = [[FORMDataSource alloc] initWithJSON:self.JSON
                                        collectionView:self.collectionView
                                                layout:self.layout
                                                values:nil
                                              disabled:NO];

    return _dataSource;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.collectionView.dataSource = self.dataSource;
}

項目主頁:http://www.baiduhome.net/lib/view/home/1425972167654


 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!