自定义Label 使用 drawRect
正常label使用,在给label赋值文字之后调用sizeToFit
- (void)drawRect:(CGRect)rect{
// 调用super的drawRect:方法,会按照父类绘制label的文字
[super drawRect:rect];
// 取文字的颜色作为删除线的颜色
[self.textColor set];
CGFloat w = rect.size.width;
CGFloat h = rect.size.height;
// 绘制(0.35是label的中间位置,可以自己调整)
UIRectFill(CGRectMake(0, h * 0.35, w, 1));
}
2017-03-30更新,升级了10.3之后,下面的方法失效了!!!
使用 NSAttributedString
NSAttributedString *attrStr = [[NSAttributedString alloc]
initWithString:_model.originPrice
attributes:@{
NSFontAttributeName:[UIFont systemFontOfSize:20.f],
NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#5bcec0"],
NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle|NSUnderlinePatternSolid),
NSStrikethroughColorAttributeName:[UIColor colorWithHexString:@"#5bcec0"]}];
self.orginPriceLabel.attributedText = attrStr;
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。