swiftのマテリアルデザイン テキストフィールドを実装
ポイントは各画面のViewのクラスはAppleのデフォルトのコントローラーに接続すること。
pod file
# Uncomment the next line to define a global platform for your project
platform :ios, '11.0'
target 'Shrine' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
use_frameworks!
# Pods for Shrine
if(ENV['TEST_BRANCH'])
pod 'MaterialComponents', :git => 'https:
elsif(ENV['TEST_COMMIT'])
pod 'MaterialComponents', :git => 'https:
elsif(ENV['TEST_TAG'])
pod 'MaterialComponents', :git => 'https:
elsif(ENV['DEFAULT_BRANCH'])
pod 'MaterialComponents', :git => 'https:
else
pod 'MaterialComponents', :git => 'https:
end
end
実装
import UIKit
import MaterialComponents
let usernameTextField: MDCTextField = {
let usernameTextField = MDCTextField()
usernameTextField.translatesAutoresizingMaskIntoConstraints = false
usernameTextField.clearButtonMode = .unlessEditing
usernameTextField.backgroundColor = .white
return usernameTextField
}()
let passwordTextField: MDCTextField = {
let passwordTextField = MDCTextField()
passwordTextField.translatesAutoresizingMaskIntoConstraints = false
passwordTextField.isSecureTextEntry = true
passwordTextField.backgroundColor = .white
return passwordTextField
}()
TODO
let usernameTextFieldController: MDCTextInputControllerOutlined
let passwordTextFieldController: MDCTextInputControllerOutlined
TODO
let cancelButton: MDCButton = {
let cancelButton = MDCButton()
cancelButton.translatesAutoresizingMaskIntoConstraints = false
cancelButton.setTitle("CANCEL", for: .normal)
cancelButton.addTarget(self, action: #selector(didTapCancel(sender:)), for: .touchUpInside)
return cancelButton
}()
let nextButton: MDCButton = {
let nextButton = MDCButton()
nextButton.translatesAutoresizingMaskIntoConstraints = false
nextButton.setTitle("NEXT", for: .normal)
nextButton.addTarget(self, action: #selector(didTapNext(sender:)), for: .touchUpInside)
return nextButton
}()
@objc func didTapNext(sender: Any) {
self.dismiss(animated: true, completion: nil)
}
@objc func didTapCancel(sender: Any) {
self.dismiss(animated: true, completion: nil)
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
TODO
usernameTextFieldController = MDCTextInputControllerOutlined(textInput: usernameTextField)
passwordTextFieldController = MDCTextInputControllerOutlined(textInput: passwordTextField)
Storyboardでもクラスが選択できる