开发者

How to draw underline to a multiline label without using CoreText?

开发者 https://www.devze.com 2023-04-03 12:50 出处:网络
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.

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?


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

TTTAttributedLabel or OHAttributedLabel


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

0

精彩评论

暂无评论...
验证码 换一张
取 消