我正在尝试这样做:
所以我正在使用这段代码:
[self.lblRound setOutlineColor:[UIColor colorWithRed:(68/255.0) green:(82/255.0) blue:(120/255.0) alpha:1]];
self.lblRound.drawOutline = YES;
但这就是我得到的:
我也试过这段代码:
lblRound.shadowColor = [UIColor colorWithRed:(68/255.0) green:(82/255.0) blue:(120/255.0) alpha:1];
lblRound.shadowOffset = CGSizeMake(0, 0);
我也确实尝试制作另一个具有所需颜色的标签并将其绘制在文本后面,但如果我正在调整文本的大小,它会影响所有文本的宽度。 我怎样才能使笔触变粗?
我不能使用图像,因为我在这段文本中有一个数字应该是可变的。
谢谢
最佳答案
解决方法:
- (void)drawRect:(CGRect)rect
{
UIFont *font=[UIFont fontWithName:@"VAGRoundedStd-Bold" size:40];
CGContextRef context = UIGraphicsGetCurrentContext();
string = lblRoundnumber;
CGSize fontWidth = [string sizeWithFont:font];
CGRect tempRect=rect;
tempRect.origin.x +=160-(fontWidth.width/2);
tempRect.origin.y +=high+42;
CGContextSetRGBStrokeColor(context, 68/255.0f, 82/255.0f, 120/255.0f, 1/1.0f);
CGContextSetRGBFillColor(context, 68/255.0f, 82/255.0f, 120/255.0f, 1/1.0f);
CGContextSetTextDrawingMode(context, kCGTextStroke);
CGContextSetLineWidth(context, 11);
[string drawInRect:tempRect withFont:font];
CGContextSetRGBFillColor(context, 1,1,1,1);
CGContextSetTextDrawingMode(context, kCGTextFill);
[string drawInRect:tempRect withFont:font];
}
关于iphone - 为标签中的文本绘制粗线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18866435/