如何围绕UILabel的前两个角? [英] How do I round only the top two corners of a UILabel?

查看:82
本文介绍了如何围绕UILabel的前两个角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在iOS 3.0+中我可以使用

I know that in iOS 3.0+ I can use

 label.layer.cornerRadius = xxx;

围绕UILabel的所有四个角(作为UIView子类),但我想只舍入标签的顶部两个角落,并保持底角成直角。

to round all four corners of a UILabel (as a UIView subclass), but I want to round only the top two corners of the label and keep the bottom corners right-angled.

我有什么方法可以用UILabel做到这一点?其他解决方案假设自定义UIView,而不是UILabel。

Is there any way I can do that with a UILabel? Other solutions assume a custom UIView, not a UILabel.

推荐答案

您可以使用CALayers和掩码

You can do this using CALayers and masks

CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.path = maskPath.CGPath;
label.layer.mask = maskLayer;

其中maskPath是使用设置的UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii

where maskPath is a UIBezierPath set up using bezierPathWithRoundedRect:byRoundingCorners:cornerRadii

这篇关于如何围绕UILabel的前两个角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆