专栏名称: Cocoa开发者社区
CocoaChina苹果开发中文社区官方微信,提供教程资源、app推广营销、招聘、外包及培训信息、各类沙龙交流活动以及更多开发者服务。
目录
相关文章推荐
51好读  ›  专栏  ›  Cocoa开发者社区

iOS 不规则(多边形)图形切图

Cocoa开发者社区  · 公众号  · ios  · 2018-03-28 09:00

正文

请到「今天看啥」查看全文


UIBezierPath *aPath = [UIBezierPath bezierPath];

//起点

NSValue * v = pointArr[0];

CGPoint p = [v CGPointValue];

CGPoint m_p = [self convertCGPoint:p fromRect1:imageV.frame.size toRect2:imageV.frame.size];

[aPath moveToPoint:m_p];

//其他点

for (int i = 1; i< pointArr.count; i++) {

NSValue * v1 = pointArr[i];

CGPoint p1 = [v1 CGPointValue];

CGPoint m_p = [self convertCGPoint:p1 fromRect1:imageV.frame.size toRect2:imageV.frame.size];

[aPath addLineToPoint:m_p];

}

[aPath closePath];

[aPath fill];

//遮罩层

UIImage *mask = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);

CGContextClipToMask(UIGraphicsGetCurrentContext(), rect, mask.CGImage);

[imageV.image drawAtPoint:CGPointZero];

UIImage *maskedImage = UIGraphicsGetImageFromCurrentImageContext();







请到「今天看啥」查看全文