ios - ios中两个Label的圆角

标签 ios objective-c uilabel native rounded-corners

我有两个标签 left 和 right mentioned 。 现在我正在尝试从左标签的左侧和右标签的右侧圆角

我试过这个:

cell.rightLabel.layer.cornerRadius = UIRectCornerBottomLeft |  UIRectCornerTopLeft;

(此代码也无法正常工作,所有边框都是圆形的..)

cell.rightLabel.layer.cornerRadius = 8;

 cell.leftlabel.layer.cornerRadius = UIRectCornerBottomRight | UIRectCornerTopRight;
  cell.leftlabel.layer.cornerRadius = 8;

最佳答案

将属性 clipsToBounds 设置为 YES 或使用 MasksToBoundsYES

cell.rightLabel.clipsToBounds = YES;
cell.leftlabel.clipsToBounds = YES;

试试这个

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.rightLabel.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft ) cornerRadii:CGSizeMake(10.0, 10.0)];

        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = cell.rightLabel.bounds;
        maskLayer.path  = maskPath.CGPath;
        cell.rightLabel.layer.mask = maskLayer;

关于ios - ios中两个Label的圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42502584/

相关文章:

ios - 在没有 segue 的情况下在 Swift 中设置接收委托(delegate)

objective-c - 如何检查方法 touchesBegan :withEvent: 中的特定事件

ios - UILabel 使用 NSTimer 更新不正确

ios - UINavigationControllerPaletteClippingView 覆盖 UIImageView 并接收点击手势

iphone - ABUnknownPersonViewController 崩溃

objective-c - 在 Objective-C 中遍历 NSDictionary

ios - Xcode 在动态 UIImageView 上垂直约束 UILabel

ios - 与 View Controller 内的自定义 UIView 交互

ios - 使用 AFNetworking 3.0 从 URL 设置 TableView Cell 图像(异步)