Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round only 2 corners of a UIView in custom UITableViewCell - iOS

I have a UIView in a custom UITableViewCell and I want to round just bottom Left and Right corners of that view. I'm doing the following, but it's not working:

- (void)awakeFromNib {
    // Initialization code

    CAShapeLayer * maskLayer = [CAShapeLayer layer];
    maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: _viewForTags.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: (CGSize){7.0, 7.0}].CGPath;

    _viewForTags.layer.mask = maskLayer;
}

I usually achieve this in usual View Controllers in the viewWillLayoutSubviews method and it works perfectly, but there's no such method when I subclass UITableViewCell.

Any idea how can I round 2 corners of a view in a subclassed UITableViewCell?

like image 628
Hyder Avatar asked Sep 26 '22 13:09

Hyder


2 Answers

actually there is a method for that state in UITableViewCell. it is layoutSubviews

-(void)layoutSubviews
{
    CAShapeLayer * maskLayer = [CAShapeLayer layer];
    maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: _im.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: (CGSize){7.0, 7.0}].CGPath;

    _im.layer.mask = maskLayer;
}
like image 93
meth Avatar answered Nov 15 '22 13:11

meth


UITableViewDelgate's

tableView:willDisplayCell:forRowAtIndexPath:

method will be called overtime when cell is about to be displayed on the screen. You can have your code in this method.

like image 37
Vishnu gondlekar Avatar answered Nov 15 '22 12:11

Vishnu gondlekar