I am facing an unexpected behavior with my UIlabel sizeToFit()
method. Now I have tried making the numberOfLines = 0
, I event called LayoutIfNeed()
. But None of them works.
I even tried methods given in this question : Vertically align text to top within a UILabel
But Again None helped. I don't have to many constraints, I am just using Auto resizing pins. I even tried it with no constraints or no auto resize.
I have this label set up in TableViewCell and CollectionReusableView. Calling it in awakeFromNib()
just doesnt affect.
UIcollectionReusableView code :
override func awakeFromNib() {
super.awakeFromNib()
label.sizeToFit()
label.numberOfLines = 0
label.layer.shadowOffset = CGSize(width: 0, height: 0)
label.layer.shadowOpacity = 3
label.layer.shadowRadius = 8
}
constrains :
TableViewCell Code:
override func layoutSubviews() {
super.layoutSubviews()
// this is the UIview on which the label is put on.
contentView.layoutIfNeeded()
}
override func awakeFromNib() {
super.awakeFromNib()
// This is the label has the issue
caption.sizeToFit()
}
Constraints :
Also, Label in the text view is stacked with Another Label and stackview constrainst are :
here is the example:
It Just doesn't seem to work. I am totally out of idea.
Any help is greatly appreciated.