【问题标题】:Draw text on screen在屏幕上绘制文本
【发布时间】:2015-02-10 18:42:53
【问题描述】:

我保持简短:我正在寻找一种简单地绘制文本的方法(类似这样的:drawTextOnScreen:(NSString)stringToDraw at:(CGPoint)point 在屏幕上就像画一条线,例如:

UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(center.x, center.y+innerRadius)]; //lower
    [path addLineToPoint:CGPointMake(center.x, center.y+outerRadius)];

对于这样的简单任务,我真的找不到简单的解决方案。

我的目标是 iOS8

【问题讨论】:

  • 使用核心动画路径层并为其设置动画。
  • 你能再解释一下吗?我什至不知道用谷歌搜索什么

标签: ios text draw


【解决方案1】:

如果您想要一种简单的方法来绘制字符串,请使用UILabel

如果你必须使用核心显卡,你可以使用[NSString drawInRect: withAttributes:]

【讨论】:

  • 我正在使用AVCaputreSession 作为相机。我喜欢将此文本显示为实际相机视图的叠加层。使用[NSString drawInRect: withAttributes:] 时这可能吗?
  • 只需添加一个 UILabel 作为 CameraView 的子视图。
【解决方案2】:

所以,我现在正在使用这个解决方案。感谢 InkGolem 的小提示。此代码将字符串“textOnScreen”写入 x=75 和 y=35 的黄色位置。

UILabel *uiLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 20, 15)];
uiLabel.text = @"textOnScreen";
uiLabel.frame=CGRectMake(75, 35, 160, 20);
uiLabel.font=[UIFont boldSystemFontOfSize:25.0];
uiLabel.textColor=[UIColor yellowColor];
uiLabel.backgroundColor=[UIColor clearColor];
[self.view addSubview:uiLabel];

【讨论】:

    猜你喜欢
    • 2013-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多