iphone - 为标签中的文本绘制粗线

标签 iphone ios objective-c xcode uilabel

我正在尝试这样做:

the needed stroke

所以我正在使用这段代码:

[self.lblRound setOutlineColor:[UIColor colorWithRed:(68/255.0) green:(82/255.0) blue:(120/255.0) alpha:1]];
 self.lblRound.drawOutline = YES;

但这就是我得到的:

what i get

我也试过这段代码:

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/

相关文章:

iphone - TabBarController setSelectedIndex - 将调用哪个委托(delegate)方法

iphone - 使用 CATransition 重新创建 iOS 应用打开过渡

objective-c - 如何在 NSPersistentDocument 和 View Controller 之间共享 NSManagedObjectContext?

iphone - 如何使 icon.png 显示在旧 iphone 上,而 icon@2x.png 显示在较新的 iPhone 上?

iphone - 为什么在 objective-c 中使用 @class

iphone - 分组 UITableView 中第一个和最后一个单元格的自定义圆角

ios - 从 UIWebview 迁移到 WKWebview

ios - 编写 sql 查询以首先将日期字符串转换为日期并执行与当前日期的匹配

iphone - TableView 单元格模糊

json - 使用逗号拆分 NSString