I am a beginner in swift and I am developing my first application. The problem I am having right now is a large text which should be displayed in a small label.text.
I have tried some of these codes:
Label.text = "The text I want to see here is too big for the size of the label"
Label.numberOfLines = 0
label.sizeToFit does not shrink text to fit the label but rather changes the size of the label to fit around the text that you have set for the label.
Without creating a new pop-up window or something like that your best bet is either shrinking the font size or allowing the label to have multiple lines of text.
For shrinking, what I would suggest is using the following:
label.adjustsFontSizeToFitWidth = true
This will shrink the size of your text to fit the label. This may end up acting weird if your text is really long compared to the width of the label, so be careful.
For multiple lines in the label try something like this:
label.lineBreakMode = NSLineBreakByWordWrapping; label.numberOfLines = 0;
Since it seems that you have no space for extra lines, what I would suggest is embedding the label in a scrollView, so that it could scroll horizontally so you can see all of the text.
This could be accomplished by the following:
var scrollView: UIScrollView = UIScrollView(frame: label.frame) //you can initialize this with the frame of your label scrollView.addSubview(label) scrollView.contentSize.height = label.frame.height scrollView.contentSize.width = label.frame.width scrollView.showsVerticalScrollIndicator = false //no vertical scroll bars