How to draw underline to a multiline label without using CoreText?
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.
- Extend UILable OR UIView.
- Implement
- (void)drawRect:(CGRect)rect
- In that method get context using `CGContextRef ctx = UIGraphicsGetCurrentContext();
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));
Set Line using this code.
CGContextSetLineWidth(ctx, 3);
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....
精彩评论