IOSのUITextField UIButtonの組み合わせ

テキストフィールドの内容に応じてボタン表示異なる画像

9967595-b54cab6df2638f09.png
image.png

インポートのUIKit
クラスのViewController:のUIViewController、UITextFieldDelegate {
のviewDidLoad FUNCオーバーライド(){
super.viewDidLoad()
//通常はペン先から、ビューをロードした後、追加の設定を行います。
(10、Y:80、幅:300、高さ:40×)RECT = CGRectせ
ましょうテキストフィールド= UITextFieldの(フレーム:RECT)
「NO銀行カード」textField.placeholder =
textField.autocorrectionType = UITextAutocorrectionType.no
textField.returnKeyType = UIReturnKeyType.done
textField.clearButtonMode = UITextFieldViewMode.whileEditing
textField.keyboardType = UIKeyboardType.numberPad
textField.keyboardAppearance = UIKeyboardAppearance.dark
textField.delegate =自己
textField.borderStyle = UITextBorderStyle.line
// textField.clearButtonMode = .whileEditing
せbtnLeft:UIButton = UIButton(タイプ:UIButtonType.custom)
btnLeft.frame = CGRect(X:0、Y:0、幅30、高さ:30)
(:のための」银行の信息」)、:UIControlState()UIImage(命名)btnLeft.setBackgroundImage
textField.leftView = btnLeft
textField.leftViewMode = .unlessEditing
ましょうbtnRight:UIButton = UIButton(タイプ:UIButtonType.custom)
btnRight.frame = CGRect( X:0、Y:0、幅30、高さ:30)
textField.rightViewMode = .always
btnRight.addTarget(自己、アクション:#selector(touchupInsideBtnAction(::)のために)、
UIControlEvents.touchUpInside)
btnRight.setBackgroundImage(UIImage (命名:」相机」)、のために:UIControlState())
textField.rightView = btnRight
self.view.addSubview(テキストフィールド)
}
textFieldShouldReturn FUNC(
テキストフィールド:UITextFieldの) - >ブール{
textField.resignFirstResponder()
戻り真
}
FUNCのtouchupInsideBtnAction(_ BTN:UIButton)
{
银行メッセージ=「模拟拍照扫描せ卡「。
(:インフォメーション警告= UIAlertControllerタイトルましょう『』、メッセージ:メッセージ、preferredStyle:UIAlertControllerStyle.alert)
しましょうOKAction = UIAlertAction(タイトル: 『OK』、スタイル:UIAlertActionStyle.default、ハンドラ:ゼロ)
alert.addAction(OKActionを)
self.present(アラート、アニメーション:真、完了:なし)
}
}

おすすめ

転載: blog.csdn.net/weixin_33719619/article/details/90866442