Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate a UILabel upside down in XCode, using Swift?

Tags:

xcode

ios

swift

I would like to have a label that is displayed upside down, when the view did load.

Here is the default code given in the ViewController.swift, and I had also added the UILabel as an outlet.

import UIKit

class ViewController: UIViewController {

    @IBOutlet var Label: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

Also sorry if this is a dumb question I am very new to IOS development and swift.

like image 403
person101 Avatar asked Oct 27 '25 10:10

person101


1 Answers

To rotate your label in viewDidLoad just use the following :

Swift

override func viewDidLoad() {
    super.viewDidLoad()
    var aLabel: UILabel = ...
    aLabel.transform = CGAffineTransformMakeRotation(M_PI)
}

Objective C

-(void) viewDidLoad {
    [super viewDidLoad];

    UILabel *aLabel = ...
    aLabel.transform = CGAffineTransformMakeRotation(M_PI);
}

M_PI will make a rotation of 180 degrees which will result in an upside down label.

like image 195
AnthoPak Avatar answered Oct 30 '25 02:10

AnthoPak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!