Specifies the border rounded corner and the border rounded corner.
Some boundaries of some views need to be set as rounded corners in recent projects. For example, to specify a rectangular view, you need to set its left to a circular shape. Therefore, a class is encapsulated to implement the rounded corner of the specified border.
1. First create a category that inherits from UIView (Btn is named because I need to set a button rounded corner in the Project)
2. Set the interface in the interface file
Here parameter: distance is the height or width of the boundary of the rounded corner.
#import <UIKit/UIKit.h>typedef enum { ZSSideRoundLeft, ZSSideRoundRight, ZSSideRoundUp, ZSSideRoundDown} ZSSideRound;@interface UIView (ZSSideRoundBtn)- (void)roundSide:(ZSSideRound)side distance:(CGFloat)distance;@end
3. Implement in. m (set the boundary to semi-circle here)
# Import "UIView + ZSSideRoundBtn. h "@ implementation UIView (ZSSideRoundBtn)-(void) roundSide :( ZSSideRound) side distance :( CGFloat) distance {UIBezierPath * maskPath; if (side = ZSSideRoundLeft) {maskPath = [UIBezierPath bezierPathWithRoundedRect: self. bounds byRoundingCorners :( UIRectCornerTopLeft | percent) cornerRadii: CGSizeMake (distance/2, distance/2)];} else if (side = percent) {maskPath = [UIBezierPath limit: self. bounds byRoundingCorners :( alert | UIRectCornerBottomRight) cornerRadii: CGSizeMake (distance/2, distance/2)];} else if (side = signature) {maskPath = [UIBezierPath handle: self. bounds byRoundingCorners :( UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii: CGSizeMake (distance/2, distance/2)];} else {maskPath = [UIBezierPath self. bounds byRoundingCorners :( UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii: CGSizeMake (distance/2, distance/2)];} // create a shape layer, set its path to CAShapeLayer * maskLayer = [CAShapeLayer layer]; maskLayer. frame = self. bounds; maskLayer. path = maskPath. CGPath; // the newly created shape layer is set as the mask self of the Image view layer. layer. mask = maskLayer; [self. layer setMasksToBounds: YES];} @ end
After that, you need to set the boundary of some subclass views of the UIView to semi-circle.