我创建了一个swift文件(test.swift):
import UIKit
func test() {
let view = UIView()
print(view)
}
Run Code Online (Sandbox Code Playgroud)
然后swiftc test.swift在终端中运行该命令.它输出
error: no such module 'UIKit'
Run Code Online (Sandbox Code Playgroud)
如何导入'UIKit'模块?
我使用可视化格式在单元格中布局子视图,如下所示:
contentView.addSubview(accountLabel)
contentView.addSubview(contentLabel)
contentView.addSubview(timeLabel)
let views: [String : Any] = [
"accountLabel": accountLabel,
"contentLabel": contentLabel,
"timeLabel": timeLabel
]
let hConstraint1 = NSLayoutConstraint.constraints(withVisualFormat: "H:|-15-[accountLabel]-[timeLabel]-8-|", options: [.alignAllCenterY], metrics: nil, views: views)
let hConstraint2 = NSLayoutConstraint.constraints(withVisualFormat: "H:[contentLabel]-8-|", options: [], metrics: nil, views: views)
let vConstraint = NSLayoutConstraint.constraints(withVisualFormat: "V:|-12-[accountLabel]-8-[contentLabel]-12-|", options: [.alignAllLeading], metrics: nil, views: views)
NSLayoutConstraint.activate(hConstraint1+hConstraint2+vConstraint)
Run Code Online (Sandbox Code Playgroud)
在模拟器中运行时它看起来不错:
但是,调试视图层次结构时会出现一些布局问题:
为什么在运行时UI看起来正常时会出现这些布局问题?
上面的可视格式字符串有问题吗?或者是Xcode的错误?
如何删除这些布局问题?