UIView,UIImageView支持顶端圆角的方式

最近在项目中需要只有顶端两个为圆角,其他的地方不改变,在网上看了很多地方,拿来的代码都不能直接使用。

所以决定自己研究一下,主要参考了

https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIBezierPath_class/Reference/Reference.html#//apple_ref/occ/clm/UIBezierPath/bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:

这个方法,以及CAShapeLayer这个方法

顶端圆角的设置,可以直接使用。后面会把画图相关的操作继续研究,发出来共享。

CAShapeLayer *styleLayer = [CAShapeLayerlayer];

    UIBezierPath *shadowPath = [UIBezierPathbezierPathWithRoundedRect:cardStyleView.boundsbyRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight) cornerRadii:CGSizeMake(8.0, 8.0)];

    styleLayer.path = shadowPath.CGPath;

    cardStyleView.layer.mask = styleLayer;

 

 

原文地址:https://www.cnblogs.com/easonoutlook/p/2811363.html