2 UITableViewCell 中 UIView 的圆角不起作用 [英] 2 Round Corners of a UIView in UITableViewCell not working

查看:141
本文介绍了2 UITableViewCell 中 UIView 的圆角不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自定义 TableViewCell 为 UIView 创建圆角.问题是当表视图加载时,它只环绕视图的左上角而不是底部.现在,当我稍微滚动表格视图时,它也会使视图的左下角部分变圆.

I am trying to create round corners for a UIView with in a custom TableViewCell. The problem is when the table view loads, it only rounds the Top Left corner of the view and not the bottom one. Now when i scroll the table view little bit, it rounds the bottom left part of the view as well.

我已经尝试了所有可能的方法,但我无法理解它.我还附上了屏幕截图以及复制代码.谢谢

I have tried every possible method but i can't get my head around it. I am also attaching the screenshots as well as copying the code. Thanks

我在自定义视图单元格类中使用的代码如下.

The code that i am using in the custom view cell class is below.

class FoodTVCell: UITableViewCell {

var food: Food!

@IBOutlet weak var foodPicture: UIImageView!
@IBOutlet weak var foodName: UILabel!
@IBOutlet weak var foodRating: UIImageView!
@IBOutlet weak var deliveryTime: UILabel!
@IBOutlet weak var minOrder: UILabel!
@IBOutlet weak var category: UILabel!
@IBOutlet weak var foodPriceLabelBG: UIView!
@IBOutlet weak var foodPrice: UILabel!


   override func awakeFromNib() {
    super.awakeFromNib()
    foodPicture.layer.cornerRadius = 75/2
    foodPicture.clipsToBounds = true

}


override func layoutSubviews() {
    super.layoutSubviews()

    let maskLayer = CAShapeLayer()
    let corners = UIRectCorner.TopLeft.union(UIRectCorner.BottomLeft)
    maskLayer.path = UIBezierPath(roundedRect: foodPriceLabelBG.bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(20.0, 20.0)).CGPath
    foodPriceLabelBG.layer.mask = maskLayer
    foodPriceLabelBG.clipsToBounds = true
}

}

推荐答案

你的 'corner rounding' 代码运行良好,问题是你的 UIView 的底部边缘超出 Cell 的底部边缘.减少您的 UIViewY 位置,它将被您的 Cell 覆盖.我也看到您的单元格的分隔线不可见,这意味着您应该在 heightForRowAtIndexPath:

Your 'corner rounding' code is working very well, the problem is that your UIView's bottom edge is going outside of your Cell's bottom edge. Decrease your UIView's Y position and it will be covered by your Cell. I see your cell's separator line invisible too, that means you should give larger height to your Cell at heightForRowAtIndexPath:

你说它在滚动时效果很好,我想它在向下滚动时有效,而在滚动到顶部时无效.这意味着您的第一个单元格在滚动到底部(第二个单元格不覆盖您的第一个单元格)时被重绘,反之亦然,同时滚动到顶部(第二个单元格覆盖您的第一个单元格)

You said it's working very well on scrolling, I suppose it's working when scrolling down and not working when scrolling to top. It means that your first cell was redrawn after second while scrolling to the bottom (where the second cell doesn't cover your first cell), and vice versa while scrolling to the top (where second cell covers your first cell)

这篇关于2 UITableViewCell 中 UIView 的圆角不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆