Pregunta
Es posible stikethrough
un UILabel
en todo?Me parece que no puede encontrar la opción...
Solución
Esta es una pregunta anterior y hay información más reciente disponible.
A partir de iOS 6, tenemos NSAttributedString .
Para iOS 6 anterior, miraría TTTAttributedLabel
Otros consejos
Podría crear otro UILabel sobre su etiqueta y usar un carácter en guión:
label.text = @"––––––––––––––––––";
Advertencia: funciona con Helvetica (sistema predeterminado). Es posible que no funcione con otras fuentes.
el iPhone no soporta atribuido cadenas (que suele ser la forma que había de hacer esto en el Cacao), así que no creemos que sea posible.
Usted podría subclase UILabel
y dibujar el strikethrough
a ti mismo.También he visto que algunas personas usan una UIWebView
para hacer este tipo de cosas, pero eso me parece demasiado para mí.
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 aplicarle un estilo con las propiedades de la etiqueta.
NSAttributedString *str=[[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%.2f", productOne.priceBefore] attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
cell.priceBefore.attributedText = str;