pulling an UIImage from a UITextView or UILabel gives white image

Posted by user293139 on Stack Overflow See other posts from Stack Overflow or by user293139
Published on 2010-03-14T22:50:56Z Indexed on 2010/03/14 22:55 UTC
Read the original article Hit count: 638

Filed under:
|
|
|
|

Hello all,

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, UIButtons) but I am just getting a white rect for my UITextView.

I've been banging my head against the wall for a while and suspect something really, really basic.

many thanks!

@interface TaskAccomplishmentViewController : UIViewController {

MKMapView *mapView;
UILabel *timeLeftText;
UITextView *challengeText;

UIButton *successButton;

-(void) setChallangeImageToImageFromChallenge {

//  works

// [currChallenge setChallengeImage:[UIImageUtils grabImageFromView:mapView]]; // [currChallenge setChallengeImage:[UIImageUtils grabImageFromView:[self view]]]; // [currChallenge setChallengeImage:[UIImageUtils grabImageFromView:successButton]];

//doesn't work

// [currChallenge setChallengeImage:[UIImageUtils grabImageFromView:timeLeftText]]; [currChallenge setChallengeImage:[UIImageUtils grabImageFromView:challengeText]];

}

and the grabImage from a UIView code

+(UIImage *)grabImageFromView: (UIView *) viewToGrab {

UIGraphicsBeginImageContext(viewToGrab.bounds.size);

[[viewToGrab layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;

}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiview