[英]Drawing outside the bounds of UITableViewCell
I am trying to add a "post-it note"-like image to all the cells in my UITableView
. 我试图在我的
UITableView
为所有单元格添加一个“便利贴”图像。 This image needs to draw (partly) outside of the bounds of the UITableViewCell
. 此图像需要(部分)绘制在
UITableViewCell
的边界之外。
When setting clipToBounds
to NO
, the image is indeed drawn outside the cell's bounds. 将
clipToBounds
设置为NO
,图像确实被绘制在单元格的边界之外。 However, (quite logically) the image is drawn below the UITableView
separator lines and section headers. 但是,(相当逻辑上)图像是在
UITableView
分隔线和节标题下面绘制的。
I guess I could try adding the images directly to the UITableView
, on top of all other elements. 我想我可以尝试将图像直接添加到
UITableView
,在所有其他元素之上。 However, it might become rather complex trying to figure out the exact location of each cell in the UITableView
, as I am using section headers. 但是,尝试在
UITableView
找出每个单元格的确切位置可能会变得相当复杂,因为我正在使用节标题。
So, before embarking on that journey, I was wondering if there might be an easier solution. 所以,在开始这段旅程之前,我想知道是否有更简单的解决方案。
You could try hiding the separator and then drawing your own separator behind the post-it in the UITableViewCell. 您可以尝试隐藏分隔符,然后在UITableViewCell中的post-it后面绘制自己的分隔符。 That should do the trick.
这应该够了吧。
I'd use an affine transform to move the post-it image to its intended location, and change the edge insets of the separator view so it isn't drawn over the image. 我使用仿射变换将后期图像移动到其预期位置,并更改分隔符视图的边缘插入,使其不会在图像上绘制。
postItImage.transform = CGAffineTransform(translationX: 50, y: 20)
separatorInset = UIEdgeInsets(top: 0, left: 30, bottom: 0, right: 50)
It depends what your UI needs to look like. 这取决于您的UI需要的样子。 This would obviously change the separator insets for all cells, which may or may not be acceptable ;-)
这显然会改变所有单元格的分隔符插入,这可能是也可能是不可接受的;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.