2009-06-28 22 views

Respuesta

3

iPhone no es compatible con cadenas atribuidas (que normalmente es la forma en que haría esto en Cocoa), por lo que no creo que sea posible.

Puede crear la subclase UILabel y dibujar el strikethrough usted mismo. También he visto a algunas personas usar UIWebView para hacer este tipo de cosas, pero eso me parece exagerado.

+0

Gracias, poco basura sin embargo! blimin Apple! –

+0

Al iniciar iOS 6, es compatible con NSAttributedString. Ver mi publicación – Stephen

3

Se puede crear otra UILabel por encima de la etiqueta y usar un guión carácter:

label.text = @"––––––––––––––––––"; 

Advertencia: trabaja con Helvetica (por defecto del sistema). Es posible que no funcione con otras fuentes.

1
UIView* slabel = [[UIView alloc] initWithFrame:CGRectMake(label.frame.origin.x, label.frame.origin.y+10, label.frame.size.width, 2)]; 
[self addSubview:slabel]; 
[slabel setBackgroundColor:label.textColor]; 

Puede agregar una vista sobre UILabel y darle un estilo con propiedades de etiqueta.

1
NSAttributedString *str=[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%.2f", productOne.priceBefore] attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}]; 

cell.priceBefore.attributedText = str;