Underline UILabel text [duplicate]

Esta pregunta ya tiene una respuesta aquí:

Subrayar texto en UIlabel 19 respuestas

Yo tengoUILabel cuya cadena se establece en tiempo de ejecución. El texto enUILabel está alineado centralmente. Quiero mostrar un subrayado debajo del texto de la etiqueta. Pero la línea debe tener X igual donde comienza el texto (considere la alineación central) y el ancho igual al ancho del texto (no el ancho de la etiqueta). Para subrayar, he creado unaUIView y ha establecido su color de fondo. Pero no puedo corregir la longitud del subrayado como quiero.

Abajo está el código que he usado:

 UILabel *blabel = [[UILabel alloc] initWithFrame:CGRectMake(XX, 6, 271, 26)];
    blabel.text = [m_BCListArray objectAtIndex:tagcount];
    blabel.textAlignment = UITextAlignmentCenter;
    blabel.backgroundColor = [UIColor clearColor];
    blabel.textColor = [UIColor whiteColor];
    blabel.font = [UIFont systemFontOfSize:14];
    [scrollDemo addSubview:blabel];

    //underline code
    CGSize expectedLabelSize = [[m_BCListArray objectAtIndex:tagcount] sizeWithFont:blabel.font constrainedToSize:blabel.frame.size lineBreakMode:UILineBreakModeWordWrap];
    CGRect newFrame = blabel.frame;
    newFrame.size.height = expectedLabelSize.height;
    blabel.frame = CGRectMake(blabel.frame.origin.x, blabel.frame.origin.y, 271, expectedLabelSize.height);
    blabel.numberOfLines = 1;
    //[blabel sizeToFit];
    int width=blabel.bounds.size.width;
    int height=blabel.bounds.size.height;

    UIView *viewUnderline=[[UIView alloc] init];
    int len = [[m_BCListArray objectAtIndex:tagcount]length];
    viewUnderline.frame=CGRectMake(XX, 26, len, 1);
    viewUnderline.backgroundColor=[UIColor whiteColor];
    [scrollDemo addSubview:viewUnderline];
    [viewUnderline release];  

¿Cómo puedo arreglar el ancho de línea de acuerdo con el texto que recibo?

Respuestas a la pregunta(3)

Su respuesta a la pregunta