I am programmatically creating a Label and textfield. I think I am on the right track but can’t figure out how to set the number of lines. I tried using “label.textRect(forBounds: , limitedToNumberOfLines: 2)” I have no clue what to put in the “forBounds” section. I tried “label”, “self”, and “self.label”.
When I check the documentation it says the parameter bound is the bounding rectangle of the receiver. Can someone please point me in the right direction for setting the number of lines? Also please let me know if there is a better way of writing the code.
func configure() {
//Create New Label
label.translatesAutoresizingMaskIntoConstraints = false
label.textColor = UIColor.black
label.text = "Pickup Location:"
label.textRect(forBounds: <#T##CGRect#>, limitedToNumberOfLines: 2)
view.addSubview(label)
//Set label Constraints
NSLayoutConstraint.activate([
label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
label.topAnchor.constraint(equalTo: view.topAnchor, constant: 299),
label.widthAnchor.constraint(equalToConstant: 71),
label.heightAnchor.constraint(equalToConstant: 41)])
//Create New TextField
textField.translatesAutoresizingMaskIntoConstraints = false
textField.backgroundColor = UIColor.white
view.addSubview(textField)
//Set textField constraints
NSLayoutConstraint.activate([
textField.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 10),
textField.topAnchor.constraint(equalTo: view.topAnchor, constant: 299),
textField.widthAnchor.constraint(equalToConstant: 295)])
}