Drawing NSString to UIImage

前端 未结 4 1741
梦毁少年i
梦毁少年i 2021-01-25 04:54

I have a NSString object. I want to write it to existing UIImage object. UIImage object already has some image associate with it. I want to write string to same image. How do i

4条回答
  •  攒了一身酷
    2021-01-25 05:15

    An NSString cannot become a UIImage. However, it sounds like all you want to do is plunk some text on top of an image, and that can be achieved easily.

    1. Create a UILabel *label. Set the text to your string with label.text = myString;.

    2. Create a UIImageView *imageView. Set the image of the view to your image with imageView.image = myimage.

    3. Add the UILabel as a subview of the UIImageView (as a subclass of UIView, it takes subviews) with [imageView addSubview:label]; (or drop the label on the imageview if you're using the IB).

    Make sure to set the background of the label to [UIColor clearColor] or set the alpha = 0.0 so that it's transparent.

提交回复
热议问题