lit*_*ium 3 uitableview ios swift
我有一个带自定义单元格的UITableView.每个单元格的结构都是这样的:我有contentView,在这个contentView中我有backView(简单的UIView有白色背景和角落半径16.0),在这个backView我有一个带有一些图片的imageView.
我想要的是让这个imageView走投无路(在他的父UIView - backView - 边框内).而且这种方式不起作用.
代码非常简单(来自ImageCell.swift):
self.backView = UIView()
self.backView.backgroundColor = UIColor.white
self.backView.translatesAutoresizingMaskIntoConstraints = false
self.backView.layer.cornerRadius = 16.0
self.contentView.addSubview(backView)
self.picture = UIImageView()
self.picture.translatesAutoresizingMaskIntoConstraints = false
self.picture.contentMode = UIViewContentMode.scaleAspectFill
self.picture.backgroundColor = UIColor.gray
self.picture.clipsToBounds = true
self.backView.addSubview(picture)
let constraintPicTop = NSLayoutConstraint(item: picture, attribute: .top, relatedBy: .equal, toItem: contentView, attribute: .topMargin, multiplier: 1.0, constant: -6)
let constraintPicLeft = NSLayoutConstraint(item: picture, attribute: .left, relatedBy: .equal, toItem: backView, attribute: .leftMargin, multiplier: 1.0, constant: -8)
let constraintPicRight = NSLayoutConstraint(item: picture, attribute: .right, relatedBy: .equal, toItem: backView, attribute: .rightMargin, multiplier: 1.0, constant: 8)
constraintBottomPic = NSLayoutConstraint(item: picture, attribute: .bottom, relatedBy: .lessThanOrEqual, toItem: contentView, attribute: .topMargin, multiplier: 1.0, constant: 150)
Run Code Online (Sandbox Code Playgroud)
我事先不知道图像的大小,因此在botForRowAt函数中更新了constraintBottomPic值.
并且它正在工作,除了这个图像没有走投无路(我相信它应该是).
(不幸的是,我不可能为UIImageView设置cornerRadius).
更新:找到解决方案.看来我必须直接在所有父视图中将'clipsToBounds'设置为true(在我的例子中是contentView和backView).
| 归档时间: |
|
| 查看次数: |
2903 次 |
| 最近记录: |