美文网首页
iOS tableviewcell里label设置半圆角问题

iOS tableviewcell里label设置半圆角问题

作者: 明似水 | 来源:发表于2020-04-14 16:43 被阅读0次

效果图如下


image.png

自定义label

NS_ASSUME_NONNULL_BEGIN

@interface HBLeftTopRadiusLabel : UILabel

@end

NS_ASSUME_NONNULL_END

.m文件

#import "HBLeftTopRadiusLabel.h"

@implementation HBLeftTopRadiusLabel

-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(8, 8)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
    self.layer.contentsScale = [[UIScreen mainScreen] scale];
}

@end

在cell里面为其他三个角添加圆角:
getter方法

-(HBLeftTopRadiusLabel *)makeRightLabel{
    if (!_makeRightLabel) {
        _makeRightLabel = ({
            HBLeftTopRadiusLabel *label = [[HBLeftTopRadiusLabel alloc] initWithFrame:CGRectZero];//初始化控件
            //常用属性
            label.text = @"奖 ¥0.0 ";//内容显示
            label.textColor = RGBA(138, 91, 54, 1);//设置字体颜色;//设置字体颜色
            label.font = FONT(10);//设置字体大小
            label.textAlignment = NSTextAlignmentCenter;//设置对齐方式
            label.numberOfLines = 1; //行数
            label.backgroundColor = RGBA(247, 213, 186, 1);
            label.layer.cornerRadius = 2;
            label.clipsToBounds = YES;
            
            label ;
        }) ;
    }
    return _makeRightLabel ;
}

喜欢就点赞吧

END.

相关文章

网友评论

      本文标题:iOS tableviewcell里label设置半圆角问题

      本文链接:https://www.haomeiwen.com/subject/zeutvhtx.html