2

I want to create a cell for my tableview like this image:

enter image description here

As you can see, in this cell I have a UIImage that have some cornerradius on its left side. I use this code for add cornerradius to my UIImage:

    ThumbnailImg .Layer .CornerRadius = 7.0f;
ThumbnailImg .Layer .MasksToBounds = true ;

But I do not know how to set radius just for let side of uiimage.

Another solution that I guess is changing uiimageview in a way that its left corner be match with corners of the cell ( I'm using grouped table width 1 row in each section), therefore the borders will create automatically. But for this way also I do not know what works should I do :-s.

I found this solution for objective-c also. can any body help using this on monotouch iphone?

https://stackoverflow.com/a/4930166

Community
  • 1
  • 1
Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115

1 Answers1

2

Subclass UIImageView to allow it drawing rounded desirable corners via UIBezierPath.

Example for UIView:

public class UIViewCustomRounded: UIView
{
    // Inspired by:
    // https://stackoverflow.com/questions/4847163/round-two-corners-in-uiview
    // https://stackoverflow.com/questions/2264083/rounded-uiview-using-calayers-only-some-corners-how/
    public UIViewCustomRounded (): base()
    {
    }

    /// <summary>
    /// Sets the corners.
    /// </summary>
    /// <param name="corners">Corners.</param>
    /// <param name="cornerRadius">Corner radius.</param>
    public void SetCorners(UIRectCorner corners, float cornerRadius)
    {
        var maskLayer = new CAShapeLayer();
        maskLayer.Frame = Bounds;
        var roundedPath = UIBezierPath.FromRoundedRect(maskLayer.Bounds, corners, new SizeF(cornerRadius, cornerRadius));
//          maskLayer.FillColor = UIColor.White.CGColor;
//          maskLayer.BackgroundColor = UIColor.Clear.CGColor;
        maskLayer.Path = roundedPath.CGPath;

        //Don't add masks to layers already in the hierarchy!
        Layer.Mask = maskLayer;
    }
}

Usage:

var a = new UIViewCustomRounded()
// Don't forget to set frame and add it as subview
a.SetCorners(UIRectCorner.BottomLeft | UIRectCorner.BottomRight, 10);

As long as UIImageView is subclass of UIView, it should be works for UIImageView too.

Reference answer.

Community
  • 1
  • 1
Maxim Korobov
  • 2,574
  • 1
  • 26
  • 44