I set up label programmatically and want to change the text of the label once a button is clicked. However, the label just displays part of the text. For example, I want to change the text from "press to start a trip" to "searching for GPS signal..", only "searching for" displayed even without "..." to indicate that there are more texts. Could someone help me with that? Thanks!
let startTravelBtn = UIButton(frame: CGRect(x: 40, y: 50, width: 50,
height: 30))
let startTipLabel = UILabel(frame: CGRect(x: 100, y: 50, width: 200, height: 30))
Hope You will get help from this
Solution
yourLabel.text = "Lorem Ipsum is simply dummy text of the printing"
yourLabel.sizeToFit()
OR
Set Lines on label to 0
Hope this will helps you.You can do this by setting numberOfLines
to 0
startTipLabel.text = "longer text what you want"
startTipLabel.numberOfLines = 0
startTipLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
public let descriptionLabel: UILabel = {
let label = PaddingLabel(withInsets: 10, 10, 10, 10)
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont(name: "Helvetica Neue Light", size: 17)
label.adjustsFontSizeToFitWidth = true
label.numberOfLines = 0
label.sizeToFit()
(label.lineBreakMode = .byWordWrapping) - doesn't also work
I tried many methods As a result, only this method (label.adjustsFontSizeToFitWidth = true) helps to avoid hiding the text.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.