iOS 为label加删除线

NSString *oldPrice = [NSString stringWithFormat:@"原价 %@",_item.previousPrice.stringValue];
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:oldPrice];
    [attr addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, oldPrice.length)];
    [_previousPriceLabel setAttributedText:attr];
时间: 2024-09-30 20:55:26

iOS 为label加删除线的相关文章

iOS 为label添加删除线

UILabel *testLabel = [[ UILabel alloc] initWithFrame:CGRectMake(10, 100, 200, 100)]; testLabel.numberOfLines = 0; NSString* strText = @"测试画删除线测试画删除线测试画删除线测试画删除线测试画删除线"; NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initW

【iOS知识学习】_iOS Label添加删除线

在做优惠价格的时候需要用到删除线,但是网上的删除线千篇一律,都是大抄小抄,其实苹果的NSAttributedString就可以实现这一点啦. 代码如下: NSString *oldPrice = @"¥ 12345"; NSUInteger length = [oldPrice length]; NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:oldPrice];

iOS · UILabel加删除线

创建自定义子类DeleteLineLabel,继承自UILabel,然后在自定义子类DeleteLineLabel中 方法一(上下文): 1 - (void)drawRect:(CGRect)rect { 2 [super drawRect:rect]; 3 4 CGContextRef ref = UIGraphicsGetCurrentContext(); 5 6 //绘制起点 7 CGContextMoveToPoint(ref, 0, rect.size.height * 0.5); 8

iOS Label添加删除线

@import url(/css/cuteeditor.css); 在做优惠价格的时候需要用到删除线,但是网上的删除线都是创建一个类继承自UILabel,然后重写drawRect方法重绘Label,其实苹果的NSAttributedString就可以实现这一点. 代码如下: NSString *lastPrice = @"¥12.25"; NSUInteger length = [lastPrice length]; NSMutableAttributedString *attri =

iOS下划线/虚线/删除线等等

1.实线,(下划线/删除线) 写一个新类 UnderLineLabel : UILabel - (void)drawRect:(CGRect)rect { // Drawing code [super drawRect:rect]; CGContextRef ctx = UIGraphicsGetCurrentContext(); CGSize fontSize =[self.text sizeWithFont:self.font forWidth:self.frame.size.width l

html基础 strong em del ins 粗体 斜体 加删除线 加下划线

礼悟:    公恒学思合行悟,尊师重道存感恩.叶见寻根三返一,江河湖海同一体.          虚怀若谷良心主,愿行无悔给最苦.读书锻炼养身心,诚劝且行且珍惜.              ide:visual studio 2017             browser:Chrome / Firefox                     os:win7 代码 <!DOCTYPE html> <html> <head> <title></tit

iOS label 添加删除线(删划线)遇到的坑

1.添加删划线方法遇到的问题 -(void)lastLabelDeal:(NSString *)str1 string:(NSString *)str2 label:(UILabel *)label{ NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  %@",str1,str2]]; [str addAtt

ios怎么实现带删除线的label

1.自己新建一个类名字为StrikeLabel,是UILabel的子类:2.在StrikeLabel.h里@property(nonatomic)BOOL strikeThroughEnabled;在StrikeLabel.m里- (void)drawRect:(CGRect)rect{ [super drawTextInRect:rect]; CGSize textSize = [[self text] sizeWithFont:[self font]]; CGFloat strikeWidt

[代码]label增加删除线

UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, 100, 30)];    [self.view addSubview:lable];    lable.backgroundColor = [UIColor redColor];    lable.textAlignment = NSTextAlignmentCenter;    NSString *oldPrice = @"¥ 999999";