iOS 为label添加删除线

UILabel *testLabel = [[ UILabel alloc] initWithFrame:CGRectMake(10, 100, 200, 100)];
    testLabel.numberOfLines = 0;
    NSString* strText = @"测试画删除线测试画删除线测试画删除线测试画删除线测试画删除线";
    NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:strText];
    NSRange contentRange = {0,[content length]};
    [content addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
    testLabel.attributedText = content;
    [self.view addSubview:testLabel];
时间: 2024-10-01 22:08:35

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

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

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

iOS Label添加删除线

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

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加删除线

NSString *oldPrice = [NSString stringWithFormat:@"原价 %@",_item.previousPrice.stringValue]; NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:oldPrice]; [attr addAttribute:NSStrikethroughStyleAttributeName value:@

给UILabel添加删除线

给UILabel添加删除线 by 伍雪颖 let attributedText = NSAttributedString(string: "道之不存,师之所存也", attributes: [NSStrikethroughStyleAttributeName:1]) self.contentLabel.attributedText = attributedText

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

Android中TextView添加删除线

项目中的需求~~~~ 商城中物品的一个本身价格,还有一个就是优惠价格...需要用到一个删除线. public class TestActivity extends Activity { private TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

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";