i have a View controller containing 2 Views, one of which contains a button. Both Views have contraints for proportional height, aspect ratio, aligning their center X(with multiplier) and bottom space(with multiplier) to superview. they both start with alpha = 0 and i fade them in with:
override func viewDidAppear(_ animated: Bool) {
UIView.animate(withDuration: 0.75, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
self.infoContainer.alpha = 1.0
self.infoContainer.frame.origin.y -= UIScreen.main.bounds.height * 0.25
self.ordersContainer.alpha = 1.0
self.ordersContainer.frame.origin.y -= UIScreen.main.bounds.height * 0.25
}, completion: nil)
}
now this worked with no problem, but now i need to change the text size of the mentioned button depending on Screen Resolution. So, i created a class:
class ScaledButton: UIButton {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
var att = titleLabel?.attributedText?.attributes(at: 0, effectiveRange: nil)
let font = att?[NSAttributedStringKey.font] as? UIFont
let size = font?.pointSize
att?[NSAttributedStringKey.font] = UIFont(name: (font?.fontName)!, size: size! * ScaledLabel.scaleFactor)
if(titleLabel?.text == nil) {return}
setAttributedTitle(NSAttributedString(string: (titleLabel?.text)!, attributes: att), for: .normal)
}
}
the static factor ScaledLabel.scaleFactor
is calculated elsewhere.
Now, when i set this class for the button in the second view, instead of starting at the position they are in the storyboard and ending the way they should, they start correctly(i believe) are moved to the correct postion instantly, then to immediatly to a postion further down and then with animation to the tsart position....
If i remove the line with setAttributedTitle
from my class it works, but obviously thats not an option. What is wrong here?