1

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216

2 Answers2

2

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

TTTAttributedLabel or OHAttributedLabel

Joshua
  • 15,200
  • 21
  • 100
  • 172
1

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....

Mohammad
  • 1,636
  • 1
  • 13
  • 17