
簡(jiǎn)單圖片.png
創(chuàng)建路徑
+ (instancetype)bezierPath;
@property(nonatomic) CGFloat lineWidth; 線寬@property(nonatomic) CGLineCap lineCapStyle; 線條拐角
@property(nonatomic) CGLineJoin lineJoinStyle; 終點(diǎn)處理
- (void)moveToPoint:(CGPoint)point; 移動(dòng)到某一點(diǎn)
- (void)addLineToPoint:(CGPoint)point; 在這個(gè)點(diǎn)與上一個(gè)點(diǎn)直接添加線
根據(jù)三個(gè)點(diǎn)繪制一條曲線,和moveToPoint配合
- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2;
根據(jù)兩個(gè)點(diǎn)繪制一條曲線,和moveToPoint配合
- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;
繪制圓形
(默認(rèn)0角度在中心的右邊) clockwise(YES為順時(shí)針)
#define kDegreesToRadians(degrees) ((3.14159265359 * degrees)/ 180)
- (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;
- (void)fill;填充路徑所圍繞的區(qū)域
- (void)stroke;連接各個(gè)點(diǎn)
- (void)closePath; 關(guān)閉路徑
創(chuàng)建矩形路徑
+ (instancetype)bezierWithRect:(CGRect)rect;
創(chuàng)建內(nèi)切圓路徑
+ (instancetype)bezierPathWithOvalInRect:(CGRect)rect;
創(chuàng)建圓角矩形
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius;
創(chuàng)建某一位置圓角的矩形
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii;
typedef NS_OPTIONS(NSUInteger, UIRectCorner) { UIRectCornerTopLeft = 1 << 0, UIRectCornerTopRight = 1 << 1, UIRectCornerBottomLeft = 1 << 2, UIRectCornerBottomRight = 1 << 3, UIRectCornerAllCorners = ~0UL
};
創(chuàng)建圓形路徑
+ (instancetype)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;
根據(jù)另一個(gè)路徑創(chuàng)建路徑
+ (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath;
路徑的一些信息
@property(readonly,getter=isEmpty) BOOL empty;@property(nonatomic,readonly) CGRect bounds;@property(nonatomic,readonly) CGPoint currentPoint;
- (BOOL)containsPoint:(CGPoint)point;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self customSubViews];
}
// 自定義子視圖
- (void)customSubViews{
UIImage *image = [self getImagewithColor:[UIColor redColor] size:CGSizeMake(100, 100) centerViewRadius:25 centerAngle:60];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100, 100, 100)];
imageView.image = image;
[self.view addSubview:imageView];
}
// 根據(jù)透明度繪制一個(gè)圖片
- (UIImage *)getImagewithColor:(UIColor *)color size:(CGSize)size centerViewRadius:(CGFloat)radius centerAngle:(CGFloat)angle{
// 聲明一個(gè)繪制大小
UIGraphicsBeginImageContext(size);
UIBezierPath *path = [UIBezierPath bezierPath];
path.lineWidth = 1;
path.lineCapStyle = kCGLineCapRound;
path.lineJoinStyle = kCGLineCapRound;
[path addArcWithCenter:CGPointMake(size.width / 2 , cos(kDegreesToRadians(angle * 0.5)) * radius) radius:radius startAngle:kDegreesToRadians(-(90 - (angle * 0.5))) endAngle:kDegreesToRadians((270 - (angle * 0.5))) clockwise:YES];
[path addLineToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(0, size.height)];
[path addLineToPoint:CGPointMake(size.width, size.height)];
[path addLineToPoint:CGPointMake(size.width, 0)];
[path addLineToPoint:CGPointMake(size.width / 2 + sin(kDegreesToRadians(angle / 2)) * radius, 0)];
[color set];
[path stroke];
// 聲明UIImage對(duì)象
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}