Pergunta

I have been trying to underline a multiline label but I am not able to do that.

I have referred to this link but this doesn't seem to help me.

How can be done without using NSAttributedString and coreText?

Foi útil?

Solução

You could use some of these open source projects from GitHub which are like UILabel's but support an attributed string:

TTTAttributedLabel or OHAttributedLabel

Outras dicas

Following steps can be helpful.

  1. Extend UILable OR UIView.
  2. Implement - (void)drawRect:(CGRect)rect
  3. In that method get context using `CGContextRef ctx = UIGraphicsGetCurrentContext();
  4. Set text you want to set using this.

    CGContextSetRGBFillColor(context,1.0, 0.0, 0.0, 1.0);
    CGContextSetTextMatrix(context,CGAffineTransformMakeTranslation(0,pageSize.height));
    CGContextSetTextDrawingMode(context, kCGTextFill);
    CGContextSelectFont(context, "Helvetica", 30, kCGEncodingMacRoman);
    char *str=(char*)[@"TEXT" UTF8String];
    CGContextShowTextAtPoint(context,476/2-200,673/2+100,str,strlen(str));
    
  5. Set Line using this code.

    CGContextSetLineWidth(ctx, 3);

  6. Draw line using this code.

    CGContextBeginPath(ctx);
    CGContextMoveToPoint(ctx, thisX, thisY);
    CGContextAddLineToPoint(ctx, thatX,thatY);
    CGContextStrokePath(ctx);

Hope above collected segments of code helps you....

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top