★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-guugthsa-km.html
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html
目錄:[Swift]通天遁地Swiftgit
本文將演示如何調整文字的對齊方式,以及建立一個可根據內容自動調整高度的文本區域。github
在項目導航區,打開視圖控制器的代碼文件【ViewController.swift】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.\nRows without title have a left-aligned text field.\nBut 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 }