我有应用程序: TextView和TableView。我创建他们的代码。现在我需要让程序自动退出。但我不知道这是怎么回事。请帮帮忙。抱歉,我的英语=)
let displayWidth: CGFloat = self.view.frame.width
let displayHeight: CGFloat = self.view.frame.height
myTextView = UITextView(frame: CGRect(x: 0, y: 20, width: displayWidth, height: displayHeight / 3))
creatTextView()
myTableView = UITableView(frame: CGRect(x: 0, y: displayHeight / 3, width: displayWidth, height: displayHeight * 2 / 3))
createTable()发布于 2017-02-22 13:14:43
快速AutoLayout指南
文档:https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/
我通常设置左侧、右侧、底部/顶部和宽度/高度约束。这可以通过多种方式实现。
一些关键词:
前导:表示对象的左边部分
尾部:表示对象的右侧部分
首先,您想要创建所有必要的变量来保存您的自动收费指南,对于您正在使用的视图,您需要将translatesAutoresizingMaskIntoConstraints设置为false,如下所示:
self.btn.translatesAutoresizingMaskIntoConstraints = false
var btnLeading: NSLayoutConstraint!
var btnBottom: NSLayoutConstraint!
var btnTop: NSLayoutConstraint!
var btnWidth: NSLayoutConstraint!我只是复制了我在一个项目中使用的一些代码,但我认为您最终会掌握它的窍门的。在我看来,self.userLocationBtn只是一个按钮,我想定位在我子类中的UIView中。
self.btnLeading = NSLayoutConstraint(
item: self.userLocationBtn,
attribute: .leading,
relatedBy: .equal,
toItem: self,
attribute: .leading,
multiplier: 1.0,
constant: 5.0)
self.btnBottom = NSLayoutConstraint(
item: self.userLocationBtn,
attribute: .bottom,
relatedBy: .equal,
toItem: self,
attribute: .bottom,
multiplier: 1.0,
constant: 0.0)
self.btnTop = NSLayoutConstraint(
item: self.userLocationBtn,
attribute: .top,
relatedBy: .equal,
toItem: self,
attribute: .top,
multiplier: 1.0,
constant: 0.0)
self.btnWidth = NSLayoutConstraint(
item: self.userLocationBtn,
attribute: .width,
relatedBy: .equal,
toItem: self,
attribute: .height,
multiplier: 1.0,
constant: 0.0)
self.addSubview(self.doneButton)添加视图后,我们需要激活约束,然后更新视图。
NSLayoutConstraint.activate([self.btnLeading, self.btnBottom, self.btnTop, self.btnWidth])
self.view.layoutIfNeeded() //Lays out the subviews immediately.https://stackoverflow.com/questions/42392072
复制相似问题