Converting Text to Image on iOS

后端 未结 4 1909
梦毁少年i
梦毁少年i 2020-12-23 23:38

How to convert Text to Image and show in UIImageview. Can anyone know the conversion from Text to Image?

4条回答
  •  不思量自难忘°
    2020-12-23 23:54

    You can start playing around with something like this:

    NSString *string = @"Some text";
    UIGraphicsBeginImageContext(CGSizeMake(80, 50));
    [string drawAtPoint:CGPointMake(10, 20)
               withFont:[UIFont systemFontOfSize:12]];
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    result contains the UIImage with the text in it, and you can assign it to the UIImageView image property.

提交回复
热议问题