pulling an UIImage from a UITextView or UILabel gives white image

前端 未结 2 624
没有蜡笔的小新
没有蜡笔的小新 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:10

    The technique is correct. Maybe it is because text is flipped. You could try to set a transform for the coordinate system and origin. Like you would normally do when drawing text.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题