pulling an UIImage from a UITextView or UILabel gives white image

前端 未结 2 623
没有蜡笔的小新
没有蜡笔的小新 2021-02-09 08:13

I need to grab an UIImage from a UITextView or UILabel. I\'ve got a method that will pull an image successfully from other types of views ( [UIViewController view], MKMapView, U

2条回答
  •  误落风尘
    2021-02-09 09:18

    I was having the same problem, getting a white rect instead of the text. To solve this, instead of using UIGraphicsBeginImageContext I used UIGraphicsBeginImageContextWithOptions and passed NO for opaque (second argument), that did the trick.

    Also passed 0.0 for scale (third argument) and to get a context with a scale factor equal to that of the screen (to look good in retina device in my case).

    Check the Apple doc about UIGraphicsBeginImageContextWithOptions here.

提交回复
热议问题