2 Round Corners of a UIView in UITableViewCell not working

℡╲_俬逩灬. 提交于 2019-12-12 03:36:28

问题


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
}

}

回答1:


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)



来源:https://stackoverflow.com/questions/36241103/2-round-corners-of-a-uiview-in-uitableviewcell-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!