我有这个Swift 4应用,并且有一个类似这样的视图控制器
View
Safe Area
Scroll View
Stack View
Label
View
Contacts View
View
Button1
View
Button2
Bottom View
我得到了一组联系人,我想为每个联系人创建标签并将其添加到Contacts View
。
var labelY = 48
for con in contacts {
let aux = try self.contactStore.unifiedContact(withIdentifier: con, keysToFetch: [CNContactGivenNameKey, CNContactFamilyNameKey] as [CNKeyDescriptor])
let label = UILabel(frame: CGRect(x: 24, y: labelY, width: 200, height: 21))
label.textAlignment = .center
label.text = "\(aux.givenName) \(aux.familyName)"
contactsView.addSubview(label)
labelY = labelY + 24
}
我遇到的问题是,当我有很多联系人时,它们在5点左右被切断,我无法滚动。
这是为什么?
答案 0 :(得分:0)
最合乎逻辑的事情是:
Contacts View
的子视图Contacts View
的所有4个面上这将导致Contacts View
随着添加的标签垂直增长。
请注意,您无需为这些标签设置框架:
for con in contacts {
let aux = try self.contactStore.unifiedContact(withIdentifier: con, keysToFetch: [CNContactGivenNameKey, CNContactFamilyNameKey] as [CNKeyDescriptor])
let label = UILabel()
label.textAlignment = .center
label.text = "\(aux.givenName) \(aux.familyName)"
contactsViewStackView.addArrangedSubview(label)
}