UIView裁剪任意边

.h

#import <UIKit/UIKit.h>

@interface UIView (Corner)
 
/**
 *  切任意角
 */
- (void)cornerWithSize:(CGSize)size andCornerPostation:(NSInteger)postation;
 
@end

.m

#import "UIView+Corner.h"
 
@implementation UIView (Corner)
 
/**
 *  裁边的可选项
 typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
 UIRectCornerTopLeft     = 1 << 0,
 UIRectCornerTopRight    = 1 << 1,
 UIRectCornerBottomLeft  = 1 << 2,
 UIRectCornerBottomRight = 1 << 3,
 UIRectCornerAllCorners  = ~0UL
 };
 */
- (void)cornerWithSize:(CGSize)size andCornerPostation:(NSInteger)postation
{
    CGRect bounds = self.bounds;
    UIBezierPath *maskPath = nil;
    maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:UIRectCornerTopLeft |  UIRectCornerBottomLeft cornerRadii:size];
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = bounds;
    maskLayer.path = maskPath.CGPath;
    [self.layer addSublayer:maskLayer];
    self.layer.mask = maskLayer;
}
 
@end

猜你喜欢

转载自blog.csdn.net/weixin_34061482/article/details/90824614