Wednesday, June 5, 2013

UIBezierPath UIRectCornerTopRight example in Objective C (iOS).


UIBezierPath UIRectCornerTopRight

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 UIRectCornerTopRight]
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 UIRectCornerTopRight 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 UIRectCornerTopRight].
CAShapeLayer *topLayer = [CAShapeLayer layer];
UIBezierPath *roundedPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
    byRoundingCorners:(UIRectCornerTopRight | UIRectCornerTopLeft)
    cornerRadii:CGSizeMake(9.f, 9.0f)];   
topLayer.path = [roundedPath CGPath];

UIBezierPath UIRectCornerTopRight example.
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(self.cornerRadius, self.cornerRadius)];
[path addClip];

[_image drawInRect:rect];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

End of UIBezierPath UIRectCornerTopRight example article.