如果你能告诉我如何以一个角度切割任何单个角落,你甚至可以获得奖金(象征性)金星.
编辑:作为参考,here’s a link到我怀疑有一个与此解决方案类似的实现的问题.我只是不知道我要改变什么.
解决方法 首先,您需要一个带角度角的路径:- (CGPathref) makeAnglePathWithRect: (CGRect)rect withSize:(float) s { CGPoint one = CGPointMake( rect.origin.x +s,rect.origin.y); CGPoint two = CGPointMake( rect.origin.x + rect.size.wIDth - s,rect.origin.y); CGPoint three = CGPointMake( rect.origin.x + rect.size.wIDth,rect.origin.y +s); CGPoint four = CGPointMake( rect.origin.x + rect.size.wIDth,rect.origin.y + rect.size.height -s); CGPoint five = CGPointMake( rect.origin.x + rect.size.wIDth-s,rect.origin.y + rect.size.height); CGPoint six = CGPointMake(rect.origin.x+s,rect.origin.y + rect.size.height); CGPoint seven = CGPointMake(rect.origin.x,rect.origin.y + rect.size.height-s); CGPoint eight = CGPointMake(rect.origin.x,rect.origin.y + s); CGMutablePathref path = CGPathCreateMutable(); CGPathMovetoPoint(path,NulL,one.x,one.y); CGPathAddlinetoPoint(path,two.x,two.y); CGPathAddlinetoPoint(path,three.x,three.y); CGPathAddlinetoPoint(path,four.x,four.y); CGPathAddlinetoPoint(path,five.x,five.y); CGPathAddlinetoPoint(path,six.x,six.y); CGPathAddlinetoPoint(path,seven.x,seven.y); CGPathAddlinetoPoint(path,eight.x,eight.y); CGPathAddlinetoPoint(path,one.y); return path;}
然后,您需要使用路径指定掩码:
CAShapeLayer *maskLayer = [CAShapeLayer layer];CGRect bounds = CGRectMake(0.0f,0.0f,100,100); //figure out your bounds[maskLayer setFrame:bounds];CGPathref p = [self makeAnglePathWithRect:bounds withSize:20.0];maskLayer.path = p;_myvIEw.layer.mask = maskLayer;
如果要从任何角落移除角度,请使用第1-8点来移除“s”值.您可以使用size参数更改从角落切出的三角形的大小.
总结以上是内存溢出为你收集整理的ios – 我怎样才能在UIView上制作弯角?全部内容,希望文章能够帮你解决ios – 我怎样才能在UIView上制作弯角?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)