Warning: Undefined array key 1 in /home/naoooooo8/naoya-ono.com/public_html/swift/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 12
Warning: Undefined array key 2 in /home/naoooooo8/naoya-ono.com/public_html/swift/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 15
Warning: Undefined array key 3 in /home/naoooooo8/naoya-ono.com/public_html/swift/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 18
Warning: Undefined array key 4 in /home/naoooooo8/naoya-ono.com/public_html/swift/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 21
Warning: Undefined array key 1 in /home/naoooooo8/naoya-ono.com/public_html/swift/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 24
Warning: Undefined array key 2 in /home/naoooooo8/naoya-ono.com/public_html/swift/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 27
Warning: Undefined array key 3 in /home/naoooooo8/naoya-ono.com/public_html/swift/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 30
Warning: Undefined array key 4 in /home/naoooooo8/naoya-ono.com/public_html/swift/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 33
テキストフィールドの左端に余白がないと、ちょっと見た目が気持ち悪いですよね。

そこで、左端に余白を設ける簡単な方法を紹介します。
実装方法
簡単なやり方は、テキストフィールド が持つ「letfView」というプロパティに、透明のViewを設定するやり方です。
次のように書きます。
class ViewController: UIViewController, UITableViewDataSource {
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
//テキストフィールドの左端に余白を設ける
let leftPadding = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 0))
leftPadding.backgroundColor = UIColor.clear
textField.leftView = leftPadding
textField.leftViewMode = .always
}
}
実際に画面を見てみると、さっきよりスッキリしました。余白のサイズは上記のwidthの値を変えることで調整できます。




