Wednesday, June 5, 2013

UIBezierPath UIRectCornerTopLeft example in Objective C (iOS).


UIBezierPath UIRectCornerTopLeft

UIRectCorner
The corners of a rectangle.

enum {
UIRectCornerTopLeft = 1 << 0,
UIRectCornerTopRight = 1 << 1,
UIRectCornerBottomLeft = 1 << 2,
UIRectCornerBottomRight = 1 << 3,
UIRectCornerAllCorners = ~0
};
typedef NSUInteger UIRectCorner;

Constants
UIRectCornerTopLeft
The top-left corner of the rectangle.
UIRectCornerTopRight
The top-right corner of the rectangle.
UIRectCornerBottomLeft
The bottom-left corner of the rectangle.
UIRectCornerBottomRight
The bottom-right corner of the rectangle.
UIRectCornerAllCorners
All corners of the rectangle.

Discussion of [UIBezierPath UIRectCornerTopLeft]
The specified constants reflect the corners of a rectangle that has not been modified by an affine transform and is drawn in the default coordinate system (where the origin is in the upper-left corner and positive values extend down and to the right).

UIBezierPath UIRectCornerTopLeft example.
UIBezierPath *bigMaskPath = [UIBezierPath bezierPathWithRoundedRect:bigView.bounds
                                 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
                                       cornerRadii:CGSizeMake(18, 18)];
UIBezierPath *smallMaskPath = [UIBezierPath bezierPathWithRoundedRect:smalLView.bounds
                                     byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
                                           cornerRadii:CGSizeMake(18, 18)];

UIBezierPath *finalPath = [UIBezierPath pathBySubtractingPath:smallMaskPath fromPath:bigMaskPath];

Example of [UIBezierPath UIRectCornerTopLeft].
CAShapeLayer *topLayer = [CAShapeLayer layer];
UIBezierPath *roundedPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
    byRoundingCorners:(UIRectCornerTopRight | UIRectCornerTopLeft)
    cornerRadii:CGSizeMake(9.f, 9.0f)];   
topLayer.path = [roundedPath CGPath];

UIBezierPath UIRectCornerTopLeft example.
if (indexPath.row == 0)
    cell.imageView.layer.mask = [Helper roundedCornerOnImage:cell.imageView onCorner:UIRectCornerTopLeft];
else if (indexPath.row == self.arrayPeople.count - 1)
    cell.imageView.layer.mask = [Helper roundedCornerOnImage:cell.imageView onCorner:UIRectCornerBottomLeft];

End of UIBezierPath UIRectCornerTopLeft example article.