長時間閱讀器,第一次張貼海報。我已經搜索了一個解決方案,但我還沒有找到一個有效的答案。垂直對齊UILabel中的文字(xcode)
好的問題:我有一個UILabel獲取動態分配給它的文本。如果我調整標籤的大小以覆蓋整個視圖控制器,則文本會卡在中間。我發現了一堆解決方案,說要添加以下代碼:
detailsLabel.numberOfLines = 0;
detailsLabel.sizeToFit()
但是,這不起任何作用。
有人可以看看我的代碼並提供建議嗎?
import UIKit
class DetailsViewController: UIViewController {
@IBOutlet weak var detailsLabel: UILabel!
@IBOutlet weak var lbldetails: UILabel!
var selectedBeach : Beach?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
detailsLabel.text = selectedBeach?.greaterDetails
lbldetails.text = (selectedBeach?.beachName ?? "") + " Details"
detailsLabel.numberOfLines = 0;
[detailsLabel .sizeToFit()]
}
@IBAction func dismiss(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
,所以我想你沒有使用自動佈局? –
嗨安德烈斯洛塔,感謝您的評論。自動佈局框在視圖控制器上被選中。 – Flexo
好的,你在故事板中設置標籤?你有沒有設置任何限制? –