zoukankan      html  css  js  c++  java
  • [Swift通天遁地]二、表格表单-(12)设置表单文字对齐方式以及自适应高度的文本区域TextArea

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(shanqingyongzhi)
    ➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/10202147.html 
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    目录:[Swift]通天遁地Swift

    本文将演示如何调整文字的对齐方式,以及创建一个可根据内容自动调整高度的文本区域。

    在项目导航区,打开视图控制器的代码文件【ViewController.swift】

    现在开始编写代码,创建星期选项表单和拥有浮动标签的文本框。

      1 import UIKit
      2 //首先在当前类文件中,
      3 //引入以及安装的第三方类库
      4 import Eureka
      5 
      6 //修改当前视图控制器类的父类的名称
      7 class ViewController: FormViewController {
      8     
      9     override func viewDidLoad() {
     10         super.viewDidLoad()
     11         
     12          //创建一个新的表单
     13         form +++
     14             //在表单中添加一个段落,并设置段落的头部区域和尾部区域
     15             Section(header: "Default field rows",
     16                     footer: "Rows with title have a right-aligned text field.
    Rows without title have a left-aligned text field.
    But this can be changed...")
     17             
     18             //添加一个名称行
     19             <<< NameRow()
     20             {
     21                 //设置该行的标题
     22                 $0.title = "Your name:"
     23                 //设置该行的占位文字
     24                 $0.placeholder = "(right alignment)"
     25             }
     26             //在当前表单行的左侧,添加一个缩略图标
     27             .cellSetup
     28             {
     29                 cell, row in
     30                 cell.imageView?.image = UIImage(named: "plus_image")
     31             }
     32             //添加一个名称行
     33             <<< NameRow()
     34             {
     35                 //设置该行的占位文字
     36                 $0.placeholder = "Name (left alignment)"
     37             }
     38             //在当前表单行的左侧,添加一个缩略图标
     39             .cellSetup
     40             {
     41                 cell, row in
     42                 cell.imageView?.image = UIImage(named: "plus_image")
     43             }
     44             
     45             //添加一个新的段落
     46             +++ Section("Customized Alignment")
     47             //添加一个名称行
     48             <<< NameRow()
     49             {
     50                 //设置该行的标题
     51                 $0.title = "Your name:"
     52             }
     53 
     54             .cellUpdate
     55             {
     56                 cell, row in
     57                 //设置文本框的文字对齐方式为左对齐
     58                 cell.textField.textAlignment = .left
     59                 //设置该行的占位文字
     60                 cell.textField.placeholder = "(left alignment)"
     61             }
     62             //添加一个名称行
     63             <<< NameRow().cellUpdate
     64             {
     65                 cell, row in
     66                 //设置文本框的文字对齐方式为右对齐
     67                 cell.textField.textAlignment = .right
     68                 //设置该行的占位文字
     69                 cell.textField.placeholder = "Name (right alignment)"
     70             }
     71             
     72             //添加一个新的段落,并设置段落的头部区域和尾部区域
     73             +++ Section(header: "Customized Text field width", 
     74                         footer: "Eureka allows us to set up a specific UITextField width using textFieldPercentage property. In the section above we have also right aligned the textLabels.")
     75             //添加一个名称行
     76             <<< NameRow()
     77             {
     78                 //设置该行的标题
     79                 $0.title = "Title"
     80                 //设置文本框的宽度比例为0.6
     81                 $0.textFieldPercentage = 0.6
     82                 $0.placeholder = "textFieldPercentage = 0.6"
     83             }
     84             .cellUpdate
     85             {
     86                 //设置文本框的对齐方式为左对齐
     87                 $1.cell.textField.textAlignment = .left
     88                 //设置文本标签的对齐方式为右对齐
     89                 $1.cell.textLabel?.textAlignment = .right
     90             }
     91             //添加一个名称行
     92             <<< NameRow() {
     93                 //设置该行的标题
     94                 $0.title = "Another Title"
     95                 //设置文本框的宽度比例为0.7
     96                 $0.textFieldPercentage = 0.7
     97                 $0.placeholder = "textFieldPercentage = 0.7"
     98             }
     99             .cellUpdate
    100             {
    101                 //设置文本框的对齐方式为左对齐
    102                 $1.cell.textField.textAlignment = .left
    103                 //设置文本标签的对齐方式为右对齐
    104                 $1.cell.textLabel?.textAlignment = .right
    105             }
    106             //添加一个新的段落,在该段落中,创建一个自适应高度的文本区域
    107             +++ Section("TextAreaRow")
    108             
    109             //添加一个文本区域行
    110             <<< TextAreaRow()
    111             {
    112                 //设置改行的占位文字
    113                 $0.placeholder = "TextAreaRow"
    114                 //设置文本区域的高度为自适应,其初始高度为110
    115                 $0.textAreaHeight = .dynamic(initialTextViewHeight: 110)
    116             }
    117     }
    118 
    119     override func didReceiveMemoryWarning() {
    120         super.didReceiveMemoryWarning()
    121         // Dispose of any resources that can be recreated.
    122     }
    123 }
  • 相关阅读:
    常量,基本运算符,if判断,while循环
    python解释器的垃圾回收机制,小整数池,变量的三个特性,is与==,与用户交互,数据类型的基本使用,基本运算符
    编程语言的分类,python解释器多版本共存.执行python的两种方式,变量,用户与程序交互
    编程简介
    bootstrap 无限极菜单
    JQuery lhgdialog使用
    mysql 不是主键不能删除的保护问题解决办法?
    遍历所有的选中的radio的个数和值
    MySQL 的 RowNum 实现
    Ibatis 测试出SQL
  • 原文地址:https://www.cnblogs.com/strengthen/p/10202147.html
Copyright © 2011-2022 走看看