自定义的圆角textField
class RoundedTextField: UITextField {
let padding = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
override func textRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
}
override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
}
override func editingRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
}
override func layoutSubviews() {
super.layoutSubviews()
self.layer.cornerRadius = 5
self.layer.masksToBounds = true
}
}
import UIKit
class NewRestaurantController: UITableViewController ,UITextFieldDelegate{
@IBOutlet weak var nameTextField: RoundedTextField!{
didSet{
nameTextField.tag = 1
nameTextField.becomeFirstResponder()
nameTextField.delegate = self
}
}
@IBOutlet weak var typeTextField: RoundedTextField!{
didSet{
typeTextField.tag = 2
typeTextField.delegate = self
}
}
@IBOutlet weak var addressTextField: RoundedTextField!{
didSet{
addressTextField.tag = 3
addressTextField.delegate = self
}
}
@IBOutlet weak var phoneTextField: RoundedTextField!{
didSet{
phoneTextField.tag = 4
phoneTextField.delegate = self
}
}
@IBOutlet weak var descriptionTextView: UITextView!{
didSet{
descriptionTextView.tag = 5
descriptionTextView.layer.cornerRadius = 5.0
descriptionTextView.layer.masksToBounds = true
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if let nextTextField = view.viewWithTag(textField.tag + 1){
textField.resignFirstResponder()
nextTextField.becomeFirstResponder()
}
return true
}
// 移除内建的方法,静态表格不需要这个在xib中已经 设置好了
}