ios – 绕UIView的一些角落,绕过视图层的边框

ios – 绕UIView的一些角落,绕过视图层的边框,第1张

概述我试图绕过UIView的底部两个角落,并且层的边框也显示为四舍五入.我目前在做: UIRectCorners corners = UIRectCornerBottomLeft | UIRectCornerBottomRight;CGSize radii = CGSizeMake(kThisViewCornerRadius, kThisViewCornerRadius);UIBezierPath 我试图绕过UIVIEw的底部两个角落,并且层的边框也显示为四舍五入.我目前在做:
UIRectCorners corners = UIRectCornerBottomleft | UIRectCornerBottomright;CGSize radii = CGSizeMake(kThisVIEwCornerRadius,kThisVIEwCornerRadius);UIBezIErPath *path = [UIBezIErPath bezIErPathWithRoundedRect:myVIEw.bounds                                           byRoundingCorners:corners                                                 cornerRadii:radii];CAShapeLayer *maskLayer = [CAShapeLayer layer];[maskLayer setPath:path.CGPath];myVIEw.layer.mask = maskLayer;

这对于正常的观点很好.但是,myVIEw的图层具有bordercolor和borderWIDth设置,从屏幕截图可以看出,图层的边框没有变圆:

我还尝试将UIVIEw子类化并从[Class layerClass]返回[CAShapeLayer层],并将视图的图层设置为形状图层,但边框最终位于视图的子视图的下方.

可以围绕视图的边框,绕过视图层的边框,并剪辑层的边框下方的子视图?

请注意,这不是关于如何舍弃一些角落而不是其他角落,而是如何让笔触行为正确.

解决方法 我想出了一种新的思维方式,感谢 David Rönnqvist的评论.

我正在尝试一个角落四舍五入,中风全都在一层.相反,我将它分解成两层:一层掩盖视图的图层绕圆角,另一层则视图添加笔触.

UIVIEw *containerVIEw = [[UIVIEw alloc] initWithFrame:someFrame];UIRectCorners corners = UIRectCornerBottomleft | UIRectCornerBottomright;CGSize radii = CGSizeMake(kThisVIEwCornerRadius,kThisVIEwCornerRadius);UIBezIErPath *path = [UIBezIErPath bezIErPathWithRoundedRect:myVIEw.bounds                                           byRoundingCorners:corners                                                 cornerRadii:radii];// Mask the container vIEw’s layer to round the corners.CAShapeLayer *cornerMaskLayer = [CAShapeLayer layer];[cornerMaskLayer setPath:path.CGPath];containerVIEw.layer.mask = cornerMaskLayer;// Make a transparent,stroked layer which will dispay the stroke.CAShapeLayer *strokeLayer = [CAShapeLayer layer];strokeLayer.path = path.CGPath;strokeLayer.fillcolor = [UIcolor clearcolor].CGcolor;strokeLayer.strokecolor = [UIcolor redcolor].CGcolor;strokeLayer.linewidth = 2; // the stroke splits the wIDth evenly insIDe and outsIDe,// but the outsIDe part will be clipped by the containerVIEw’s mask.// transparent vIEw that will contain the stroke layerUIVIEw *strokeVIEw = [[UIVIEw alloc] initWithFrame:containerVIEw.bounds];strokeVIEw.userInteractionEnabled = NO; // in case your container vIEw contains controls[strokeVIEw.layer addSublayer:strokeLayer];// configure and add any subvIEws to the container vIEw// stroke vIEw goes in last,above all the subvIEws[containerVIEw addSubvIEw:strokeVIEw];
总结

以上是内存溢出为你收集整理的ios – 绕UIView的一些角落,绕过视图层的边框全部内容,希望文章能够帮你解决ios – 绕UIView的一些角落,绕过视图层的边框所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1113194.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存