Created
June 13, 2024 08:40
-
-
Save yccheok/6f1b4cdd7693731b6b2b4dd625b536cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class TodoInputAccessoryView: UIView { | |
@IBOutlet weak var textView: UITextView! | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
commonInit() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
commonInit() | |
} | |
override func awakeFromNib() { | |
super.awakeFromNib() | |
textView.inputAccessoryView = self | |
DispatchQueue.main.async { | |
self.textView.becomeFirstResponder() | |
} | |
} | |
private func commonInit() { | |
let screenRect = UIScreen.main.bounds | |
let screenWidth = screenRect.size.width | |
self.translatesAutoresizingMaskIntoConstraints = true | |
self.frame = CGRect( | |
x: 0, | |
y: 0, | |
width: screenWidth, | |
height: 250 | |
) | |
// Not sure why using auto layout is not working. | |
/* | |
let screenRect = UIScreen.main.bounds | |
let screenWidth = screenRect.size.width | |
self.translatesAutoresizingMaskIntoConstraints = false | |
// Set up constraints | |
NSLayoutConstraint.activate([ | |
self.widthAnchor.constraint(equalToConstant: screenWidth), | |
self.heightAnchor.constraint(equalToConstant: 150) | |
]) | |
*/ | |
self.clipsToBounds = true | |
self.layer.cornerRadius = 16 | |
self.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment