LoginSignup
0
0

More than 1 year has passed since last update.

UITextField leftViewについて

Last updated at Posted at 2021-10-08

今回の内容

C99FB5BC-363D-4DEC-BF45-A6C159D1E98C_1_201_a.jpeg

コードと簡単解説

  • .leftViewを設定することで、TextField内の左側にUIViewを作成することが出来ます。

  • .leftViewが存在すると入力される文字の位置が.leftViewのframe分だけ横に移動します。

        let textfield01 = UITextField()
        textfield01.frame = CGRect(x: view.frame.maxX / 10, y: view.frame.maxY / 11, width: view.frame.width - (view.frame.maxX / 5), height: 50)
        textfield01.placeholder = "UITextField01"
        textfield01.layer.cornerRadius = 10.0
        textfield01.layer.borderWidth = 1.0
        textfield01.leftView = UIView(frame: CGRect(x: 2, y: 2, width: textfield01.frame.height, height: textfield01.frame.height))
        textfield01.leftView?.backgroundColor = .systemGreen
        textfield01.leftViewMode = .always
        textfield01.layer.borderColor = UIColor.black.cgColor
        textfield01.backgroundColor = .white
        view.addSubview(textfield01)

終わり

ご指摘、ご質問などありましたら、コメントまでお願い致します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0