的UILabel出现在调试视图的层次结构,但不是在应用程序 [英] UILabel appear in debug view hierarchy but not in the application
问题描述
我有我的ViewController通过添加界面生成器一个UIView。
I have a UIView that I added in ViewController through the Interface Builder.
在我的code,我在这个UIView的每一个按钮是pressed时间创建一个标签:
In my code, I create a label in this UIView every time that a button is pressed:
func addToDisplay(stringToDisplay: String) {
let label = UILabel(frame: CGRectMake(0, 0, 10, 10))
label.text = stringToDisplay
label.textColor = UIColor.redColor()
label.textAlignment = .Right
label.sizeToFit()
label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.5
label.setTranslatesAutoresizingMaskIntoConstraints(false)
var lastLabel: UILabel?
if displayView.subviews.count > 0 {
lastLabel = displayView.subviews[displayView.subviews.count - 1] as? UILabel
}
displayView.addSubview(label)
var viewsDictionary = ["displayView": displayView, "label": label]
// add constraints
if let lastLabel = lastLabel {
viewsDictionary["lastLabel"] = lastLabel
displayView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[label(==20)]-0-[lastLabel]", options: nil, metrics: nil, views: viewsDictionary))
} else {
displayView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[label(==20)]-0-|", options: nil, metrics: nil, views: viewsDictionary))
}
displayView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[label]-0-|", options: nil, metrics: nil, views: viewsDictionary))
}
当我preSS的按钮,没有出现我的设备(也没有在模拟器上),但是当我检查的观点调试层次,它的存在的。我不明白为什么。任何想法?
When I press the button, nothing appear on my device (nor on the simulator) but when I check the view debug hierarchy, it's there. I don't understand why. Any idea?
编辑:
下面是两张截图:
EDIT2:
通过改变阿尔法比0不同的东西解决了...
Solved by changing alpha to something different than 0...
推荐答案
好吧,我想你需要告诉视图更新约束,写检查:
Well I think you need to tell the view to update constraints, write this and check:
[displayView updateConstraintsIfNeeded];
也测试你的 displayView
添加到 self.view
!
您正在使用的导航栏?如果是的话那么它是半透明
?如果是的话那么你的self.view可能会从开始的(0,0)和导航栏是它的上面。如果这样的话,那么给予一定的 X'放大器;是,说的(100,100)并检查是否显示。
Also test that your displayView
is added to self.view
!
Are you using Navigation Bar? If yes then is it translucent
? If yes then your self.view may be starting from (0,0) and Navigation Bar is top of it. If this the case then give some x & y, say (100, 100) and check if it shows.
让我们知道,如果这有助于。
Let us know if this helped.
这篇关于的UILabel出现在调试视图的层次结构,但不是在应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!