2016-05-17 26 views
-1

Also hatte ich eine Pause von iOS Dev für 4 Monate und es scheint, dass ich alles vergessen habe. Alles, was ich versuche, ist ein Label programmatisch auf 0,0, Größe 200,50. Ich habe gehört, dass es ein paar Änderungen in iOS8 gibt, an die ich mich nicht erinnern kannSwift: UILabel programmatisch Einschränkungen hinzufügen

let x : CGFloat = 0.0 
let y : CGFloat = 0.0 
let width : CGFloat = 200.0 
let height : CGFloat = 50.0 
self.label = UILabel(frame: CGRect(x: x, y: y, width: width, height: height)) 
self.label.text = "SIMON" 
self.label.textColor = UIColor.whiteColor() 

self.label.font = UIFont(name: "HelveticaNeue-UltraLight", size: 24) 
self.label.textAlignment = NSTextAlignment.Center 
self.label.backgroundColor = UIColor.redColor() 
self.label.layer.masksToBounds = true; 
self.label.layer.cornerRadius = 8.0; 
self.label.adjustsFontSizeToFitWidth = true; 

self.label.translatesAutoresizingMaskIntoConstraints = false 

widthConstraint = NSLayoutConstraint(item: self.label, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: width) 

heightConstraint = NSLayoutConstraint(item: self.label, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: height) 

leftConstraint = NSLayoutConstraint(item: self.label, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.LeadingMargin, multiplier: 1, constant: x) 

topConstraint = NSLayoutConstraint(item: self.label, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.TopMargin, multiplier: 1, constant: y) 

self.view.addSubview(self.label) 

NSLayoutConstraint.activateConstraints([leftConstraint,topConstraint, widthConstraint, heightConstraint]) 

Antwort

0

Es scheint, ich war Dump!

Es war das Ereignis, von dem ich anrief, nicht der Code. Zur Ansicht verschobenWillAppear

Verwandte Themen