style capable bar apps apple app iphone objective-c uitableview fonts

iphone - capable - web app ipad



Fuente de huelga en el objetivo C (10)

¿Has pensado en encontrar tu propia fuente tachada y cargarla tú mismo? No es tan difícil, solo agregue el UIFont a su archivo Info.plist y ponga el nombre de la fuente allí. Luego, puede configurar manualmente el texto para esa nueva fuente tachada.

Ver esta publicación en la carga de fuentes personalizadas.

¿Puedo incrustar una fuente personalizada ...

¿Cómo puedo usar la fuente tachada en el objetivo C? Más específicamente en UITableViewCell

cell.textLabel.text = name; cell.detailTextLabel.text = quantity ; cell.XXX = ??


1-Obtener el tamaño del texto que necesita tacharse

CGSize expectedLabelSize = [string sizeWithFont:cell.titleLabel.font constrainedToSize:cell.titleLabel.frame.size lineBreakMode:UILineBreakModeClip];

2-Crea una línea y agrégala al texto.

UIView *viewUnderline = [[UIView alloc] init]; viewUnderline.frame = CGRectMake(20, 12, expectedLabelSize.width, 1); viewUnderline.backgroundColor = [UIColor grayColor]; [cell addSubview:viewUnderline]; [viewUnderline release];


Aquí es cómo tachar a través de su etiqueta. Pero recuerda, sólo funciona después de iOS 6.0.

NSNumber *strikeSize = [NSNumber numberWithInt:2]; NSDictionary *strikeThroughAttribute = [NSDictionary dictionaryWithObject:strikeSize forKey:NSStrikethroughStyleAttributeName]; NSAttributedString* strikeThroughText = [[NSAttributedString alloc] initWithString:@"Striking through it" attributes:strikeThroughAttribute]; strikeThroughLabel.attributedText = strikeThroughText;


El tachado es posible mediante el uso de NSStrikeThroughAttributes y attribText de UILabel. Aquí está la solución en Swift

let strikeThroughAttributes = [NSStrikethroughStyleAttributeName : 1] let strikeThroughString = NSAttributedString(string: "Text of Label", attributes: strikeThroughAttributes) strikeThroughLabel.attributedText = strikeThroughString


Esto golpeará a través de toda la célula. En caso de que lo necesite para verse como una tarea completada:

CGSize size = cell.contentView.frame.size; // you''ll draw the line in whole cell. UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15,size.height / 2,size.width - 30, 1)]; line.backgroundColor = [UIColor grayColor]; // set your preferred color [cell addSubview:line];

Puede indicar algún otro valor en CGRectMake en lugar de 15; está compensado por X. En este caso, es mejor que disminuya el ancho por el valor duplicado (en mi caso es 15 * 2 = 30) para que se vea bien.


este es Marin, el autor del capítulo de cadenas atribuidas en "iOS6 by Tutorials".

Desde iOS6, en realidad hay un soporte nativo para un montón de atributos de texto diferentes, incluido el tachado.

Aquí hay un breve ejemplo, que puede usar para la etiqueta de texto de su celda:

NSDictionary* attributes = @{ NSStrikethroughStyleAttributeName: [NSNumber numberWithInt:NSUnderlineStyleSingle] }; NSAttributedString* attrText = [[NSAttributedString alloc] initWithString:@"My Text" attributes:attributes]; cell.textLabel.attributedText = attrText;

Eso es todo. ¡Buena suerte!


EDITAR: Esta respuesta está desactualizada a partir de iOS 6. Consulte las respuestas más recientes a continuación.

No hay soporte nativo para las fuentes de acceso directo o subrayado. Tienes que dibujar las líneas sobre las vistas para las etiquetas.

Esto es una tontería ya que el inspector de fuentes para IB tiene opciones para establecer tachado y subrayado, pero estas se ignoran rápidamente si intenta establecerlas.


CGRect frame = sender.titleLabel.frame; UILabel *strikethrough = [[UILabel alloc] initWithFrame:frame]; strikethrough.opaque = YES; strikethrough.backgroundColor = [UIColor clearColor]; strikethrough.text = @"------------------------------------------------"; strikethrough.lineBreakMode = UILineBreakModeClip; [sender addSubview:strikethrough];


NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"Your String here"]; [attributeString addAttribute:NSStrikethroughStyleAttributeName value:@2 range:NSMakeRange(0, [attributeString length])]; yourLabel.attributedText = attributeString;


UIView *strikeView = [[UIView alloc] initWithFrame:ccr(0, 0, myLabel.bounds.size.width, 1)]; strikeView.backgroundColor = [UIColor redColor]; strikeView.center = ccp(myLabel.bounds.size.width/2, myLabel.bounds.size.height/2); [myLabel addSubview:strikeView];