Ios 如何设置UIView在Swift中显示在状态栏下方的约束?
这里是这样的:我有一个nib文件,其中有一个自定义的Ios 如何设置UIView在Swift中显示在状态栏下方的约束?,ios,swift,uiview,constraints,Ios,Swift,Uiview,Constraints,这里是这样的:我有一个nib文件,其中有一个自定义的UIToolbar。我将此nib文件加载到我的UINavigationController(因此,当用户使用应用程序时,它将出现在任何地方)。但是,当我添加子视图时,它会显示在状态栏下。由于我是新手,又快又有限制,我需要你们的帮助,各位:) 这是我的密码: override func viewDidLoad() { super.viewDidLoad(); var statusBarHeight = UIApplication
UIToolbar
。我将此nib文件加载到我的UINavigationController
(因此,当用户使用应用程序时,它将出现在任何地方)。但是,当我添加子视图时,它会显示在状态栏下。由于我是新手,又快又有限制,我需要你们的帮助,各位:)
这是我的密码:
override func viewDidLoad() {
super.viewDidLoad();
var statusBarHeight = UIApplication.sharedApplication().statusBarFrame.size.height
var toolbarView = self.loadFromNibNamed("toolbarView")!
toolbarView.setTranslatesAutoresizingMaskIntoConstraints(false);
self.view.addSubview(toolbarView);
self.view.bringSubviewToFront(toolbarView);
let statusBarConstraint = NSLayoutConstraint(item: toolbarView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: statusBarHeight)
self.view.addConstraint(statusBarConstraint)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadFromNibNamed(nibNamed: String, bundle : NSBundle? = nil) -> UIView? {
return UINib(
nibName: nibNamed,
bundle: bundle
).instantiateWithOwner(self, options: nil)[0] as? UIView
}
如何使用NSLayoutConstraint
将我的子视图设置为显示在状态栏的右下方,而不是更改帧的原点.y