Search code examples
iosipadautolayoutviewwillappear

UILabel text size is not getting updated for iPad when the view appears first time


I have a label on my screen which is given marque behaviour. Using size classes I made the label size to a specific size for iPad. When the view appears on screen, the label size is smaller.But, when I navigate to next view and come back to that view, the label size is changed as expected. I want the size to be changed first time the view appears. What is the issue?

I wrote the following code in viewWillAppear

lblScrollingNotification.frame.origin.x = ScreenSize.SCREEN_WIDTH
    lblScrollingNotification.text = "This is a sample text to check the animation of the text in home screen"
    lblScrollingNotification.sizeToFit()
    UIView.animate(withDuration: 12.0, delay: 1, options: ([.curveLinear, .repeat]), animations: {() -> Void in

        self.lblScrollingNotification.center = CGPoint(x: self.lblScrollingNotification.bounds.size.width / 2, y : self.lblScrollingNotification.center.y)

    }, completion:  { _ in })

Solution

  • I wrote the above code in viewDidLayoutSubviews instead of viewWillAppear. That solved the issue.