다음 코드에서 UIKeyboard는 뷰보다 큽니다.
질문 : 키보드를 뷰와 같은 크기로 만드는 방법은 무엇입니까?
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController, UITextFieldDelegate {
override func loadView() {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
view.backgroundColor = .white
let label = UITextField()
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
label.text = "Hello World!"
label.textColor = .black
label.addTarget(self, action: #selector(myTargetFunction), for: .touchDown)
view.addSubview(label)
self.view = view
}
@objc func myTargetFunction() {
print("It works!")
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
지금까지 발견 한 유일한 "솔루션"은 preferredContentSize
UIViewController를 UIScreen.main
현재 Xcode Playground 환경 의 크기 로 설정하는 것 입니다 .
let vc = MyViewController()
vc.preferredContentSize = UIScreen.main.bounds.size
PlaygroundPage.current.liveView = vc
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다