Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8639655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:04:25+00:00 2026-06-12T11:04:25+00:00

I hope that title makes some sense. I have UIView (created in IB) where

  • 0

I hope that title makes some sense.

I have UIView (created in IB) where I add stuff (images). Then, I have a UILabel with some text. Now, I want to make a UIImage out of that, which I do like this:

UIView *comp = [[UIView alloc] initWithFrame:self.previewView.frame];
    [comp addSubview:self.previewView];
    [comp addSubview:self.lblCaption];

    UIGraphicsBeginImageContextWithOptions(comp.bounds.size, NO, 1.0);
    [comp.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

self.previewView and self.lblCaption are both created in IB. previewView is just a screen-filling view.

The code-block is executed in an IBAction after a button-tap.

Which works wonderful, I get the image as expected and can process it further.

But after that, the contents of «self.previewView» are gone? When I do an NSLog, everything seems to be there, but it’s not visible on screen anymore.

Does anyone have an idea what’s going on here?

[Edit]

As the answer below states, the view was added to self.view before, so it was removed when I added it to the comp. The solution is pretty easy, actually, I changed the code to the following: (created a function that returns a UIImage. That’s a bit cleaner than doing it in code….

-(UIImage *)imageFromView:(UIView *)theView andLabel:(UILabel *)theLabel{

    UIGraphicsBeginImageContextWithOptions(comp.bounds.size, NO, 1.0);
    [theView.layer renderInContext:UIGraphicsGetCurrentContext()];
    [theLabel.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return viewImage;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:04:27+00:00Added an answer on June 12, 2026 at 11:04 am

    I am just guessing assuming possible situations…

    Assuming you were showing self.previewView on some other view, say self.view.

    When you added self.previewView to comp, it may have been removed from self.view. (Considering that UIView.superview is only single instance, I am thinking this is very likely).

    If this is the case, re-adding self.previewView to self.view after obtaining image would solve the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope the title makes sense. I have a set of items that I
I hope that title makes sense.... Basically I created PHP script to take data
Ok my first post and i hope the title makes sense. I have an
I hope this title makes sense - I need case-insensitive regex matching on BlackBerry
I'm not sure if the title makes sense, but I hope you can understand
I have text that was created created with CKeditor , and it seems to
Hope that someone can share their experience with some of the latest emerging backbone.js
I had some problem formulating the question in the title, but i hope you
I have some code that grabs some rows from a table and I want
I have some records that were imported to SQL. One of the fields 'FieldToChage'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.