iOS tableviewcell里label设置半圆角问题
2020-04-14 本文已影响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.