Search code examples
iphonequartz-2d

Setting Corners in View


I know that I can make UIView with Rounded Corner as

view.layer.cornerRadius = 10;

Now I would like to know how can I make round corner on selected corners? Like making it on top left and top right and not in bottom left and bottom right. How could I do these?

Thanks in advance...


Solution

  • Something like this will draw only top corners -

    - (void)drawRect:(CGRect)rect
    {
    [super drawRect:rect];
    
    UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(44.5, 12.5, 69, 46) byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: CGSizeMake(10, 10)];
    [[UIColor whiteColor] setFill];
    [roundedRectanglePath fill];
    
    [[UIColor blackColor] setStroke];
    roundedRectanglePath.lineWidth = 0.5;
    [roundedRectanglePath stroke];
    

    }