首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自动编程快速输出

自动编程快速输出
EN

Stack Overflow用户
提问于 2017-02-22 12:53:31
回答 1查看 107关注 0票数 1

我有应用程序: TextView和TableView。我创建他们的代码。现在我需要让程序自动退出。但我不知道这是怎么回事。请帮帮忙。抱歉,我的英语=)

代码语言:javascript
复制
    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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-22 13:14:43

快速AutoLayout指南

文档:https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/

我通常设置左侧、右侧、底部/顶部和宽度/高度约束。这可以通过多种方式实现。

一些关键词:

前导:表示对象的左边部分

尾部:表示对象的右侧部分

首先,您想要创建所有必要的变量来保存您的自动收费指南,对于您正在使用的视图,您需要将translatesAutoresizingMaskIntoConstraints设置为false,如下所示:

代码语言:javascript
复制
self.btn.translatesAutoresizingMaskIntoConstraints = false

var btnLeading: NSLayoutConstraint!
var btnBottom: NSLayoutConstraint!
var btnTop: NSLayoutConstraint!
var btnWidth: NSLayoutConstraint!

我只是复制了我在一个项目中使用的一些代码,但我认为您最终会掌握它的窍门的。在我看来,self.userLocationBtn只是一个按钮,我想定位在我子类中的UIView中。

代码语言:javascript
复制
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)

添加视图后,我们需要激活约束,然后更新视图。

代码语言:javascript
复制
NSLayoutConstraint.activate([self.btnLeading, self.btnBottom, self.btnTop, self.btnWidth])

self.view.layoutIfNeeded() //Lays out the subviews immediately.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42392072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档