![](/img/trans.png)
[英]How to allow only single UIViewController to rotate upside down with Xcode?
[英]How to rotate a UILabel upside down in XCode, using Swift?
當視圖加載時,我想要一個倒置顯示的標簽。
這是ViewController.swift中給出的默認代碼,我還添加了UILabel作為插座。
import UIKit
class ViewController: UIViewController {
@IBOutlet var Label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
也很抱歉,如果這是一個愚蠢的問題,我對IOS開發和swift非常新。
要在viewDidLoad
旋轉標簽,只需使用以下內容:
迅速
override func viewDidLoad() {
super.viewDidLoad()
var aLabel: UILabel = ...
aLabel.transform = CGAffineTransformMakeRotation(M_PI)
}
目標C.
-(void) viewDidLoad {
[super viewDidLoad];
UILabel *aLabel = ...
aLabel.transform = CGAffineTransformMakeRotation(M_PI);
}
M_PI
將旋轉180度,這將導致標簽顛倒。
Swift 3x,Xcode 8x
override func viewDidLoad() {
super.viewDidLoad()
var aLabel: UILabel = ...
aLabel.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI))
}
Xcode 8.3.3
override func viewDidLoad() {
super.viewDidLoad()
var aLabel: UILabel = ...
aLabel.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.