我一直在创建一个应用程序,其 View 与 AppStore (iOS 11) - {Today} View 相同。
只是想知道我如何处理该 View 。然而,我认为方法是创建一个带有 UITableViewDataSource 和 -Delegate 扩展名的 UIViewController,我可以在我的 ViewController 中获取行数和数据。在 dequeReusableCell 中,我创建了一个 UITableViewCell 类,我在其中以编程方式创建了一个 UIView,但这不起作用。
class MyTableViewCell: UITableViewCell {
let cellView:UIView = {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
view.layer.cornerRadius = 15
view.backgroundColor = UIColor.clear
view.layer.shadowColor = UIColor.black.cgColor
view.layer.shadowOpacity = 1
view.layer.shadowOffset = CGSize.zero
view.layer.shadowRadius = 5
return view
}()
}
在上面的类片段中,无法在主视图中插入我的 UIView。
没有添加 View 的方法(很明显),因为它在 UIViewController 而不是 UITableViewCell 下。 所以我的问题是如何在 tableViewCell 中获取 UIView
或者是否有任何其他方法可以像 ios 11 Today 选项卡 View 一样获取精确的 View 单元格?这就是我想要的 ->
我已经升级了我的问题,请[这里]看看 1 : How to nest a UICollectionViewCell inside another one?
最佳答案
您可以像这样将 customView 添加到 uitableviewcell。
class MyTableViewCell: UITableViewCell {
let cellView: UIView = {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
view.layer.cornerRadius = 15
view.backgroundColor = UIColor.white
view.layer.shadowColor = UIColor.black.cgColor
view.layer.shadowOpacity = 1
view.layer.shadowOffset = CGSize.zero
view.layer.shadowRadius = 5
return view
}()
override func awakeFromNib() {
super.awakeFromNib()
addSubview(cellView)
}
}
关于ios - 如何以编程方式在 UITableViewCell 中添加 UIView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52201273/