ios - 无法添加标签以查看
问题描述
我正在尝试以contactsView
编程方式向视图添加标签,但由于某种原因它没有被添加。这是我的代码,我没有收到任何错误,但什么也没得到。
我已经尝试调用 getContacts()viewWillAppear
但仍然没有
class ModuleViewController: UIViewController {
@IBOutlet weak var contactsView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
getContacts()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
fileprivate func getContacts() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
label.center = CGPoint(x: 160, y: 285)
label.textAlignment = .center
label.textColor = .black
label.text = "Test"
self.contactsView.addSubview(label)
}
}
解决方案
问题是这一行:
label.center = CGPoint(x: 160, y: 285)
它将标签移出您看不到的联系人视图。
推荐阅读
- swift - 在 Swift 中使用嵌套字典类型确定字典
- javascript - 动态 iframe 加载 Jquery
- python - pygame : while 运行一次并停止
- python - Python Selenium - 不再找到文本时关闭驱动程序
- python - 如何根据 Python 中的位置参数与 argparse 的组合设置不同的选项?
- python - ImportError:无法从“电报”导入名称“Bot”
- jquery - 使父项文本(不仅仅是箭头)打开子菜单?
- python - 基于误差精度的自动舍入方法
- hana - SAP DBTech JDBC:[260]:无效的列名 - HANA (Studio) 和 SQL SERVER (MST) 的 SQL 产生不同的结果
- python - TypeError:将数据帧传递给管道时,int对象不可下标