So I have a normal UILabel inside UIView with some words inside. It is a 3 lines label and has .adjustsFontSizeToFitWidth = true
Most of the time it works fine but in some cases there is hyphenation of words, like this:
But in other combinations of letters it is like i want/need, it doesn't hyphen and just adjust the size:
What I need is to force UILabel not to break/hyphen words and instead prefer adjusting the size. Line breaks modes don't do much here. Is there a way that I am missing to turn off the word hyphen or breaking? I also have tried to find out how to check if the word was breaked but was unable to find it either so I can adjust the number of lines for example.
Edit: here is playground code to have a look:
import Foundation
import UIKit
import PlaygroundSupport
public class Card: UIView {
var label2: UILabel!
public init(frame: CGRect, withText: String) {
super.init(frame: frame)
self.backgroundColor = UIColor(red: 0.313, green: 0.89, blue: 0.76, alpha: 1.000)
label2 = UILabel(frame: CGRect(x: bounds.width / 2 - 115, y: (bounds.height/2 - 90), width: 230, height: 180))
label2.textAlignment = .center
label2.text = "stepper; rotory; revolutionizing"
label2.font = UIFont.boldSystemFont(ofSize: 60)
label2.textColor = UIColor.white
label2.adjustsFontSizeToFitWidth = true
label2.translatesAutoresizingMaskIntoConstraints = false
label2.numberOfLines = 0
self.addSubview(label2)
// label2.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
// label2.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -50).isActive = true
// label2.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 50).isActive = true
// label2.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
let card = Card(frame: CGRect(x: 10, y: 30, width: 280, height: 200), withText: "💜")
let page = PlaygroundPage.current
let view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 500))
view.backgroundColor = UIColor.white
view.addSubview(card)
page.liveView = view