Có, bạn có thể hiển thị văn bản được phác thảo với sự trợ giúp của CGContextSetDrawingMode(CGContextRef, CGTextDrawingMode)
, mặc dù có thể bạn sẽ cần phải điều chỉnh một số số và màu sắc để làm cho nó trông đẹp.
Điều này có vẻ hợp lý khi sử dụng kCGTextFillStroke, nhưng điều đó có thể khiến cho hành trình vượt quá mức lấp đầy. Nếu bạn đột quỵ, sau đó điền vào, như trong khối dưới đây, bạn sẽ có được một phác thảo có thể nhìn thấy đằng sau văn bản có thể đọc được.
CGContextRef context = UIGraphicsGetCurrentContext();
CGPoint point = CGPointMake(0,30);
CGFloat fontSize = (3 * MKRoadWidthAtZoomScale(zoomScale));
UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];
// Draw outlined text.
CGContextSetTextDrawingMode(context, kCGTextStroke);
// Make the thickness of the outline a function of the font size in use.
CGContextSetLineWidth(context, fontSize/18);
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
[text drawAtPoint:point withFont:font];
// Draw filled text. This will make sure it's clearly readable, while leaving some outline behind it.
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetFillColorWithColor(context, [[UIColor blueColor] CGColor]);
[text drawAtPoint:point withFont:font];
Rất cám ơn ... nó đã hoạt động rất tốt !! – user836026
không hoạt động trong trường hợp của tôi, tôi đã làm theo các bước tương tự –