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 8666259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:41:00+00:00 2026-06-12T17:41:00+00:00

in my application I have a class name playGrid which contains three objects, an

  • 0

in my application I have a class name playGrid which contains three objects, an NSArray of images named plays, and two NSUIntegers rowCount and columCount for the amount of rows and columns in the popover that will be used.

For this example, I have 6 images and I am trying to show them over 2 columns and three rows. I am trying to display these views in a popover. Previously I was able to do this with blocks of colors, but now that I am trying to do with images I am unable to generate the popover correctly. Listed below is my drawRect code for the successful popover that shows the colors.

How would I convert this to work with UIImages instead of the colors?

In the example below, rowCount and columnCount are 2 and 3 just like the one we are trying to make, but the array is named colors, and contains six UIColor items.

- (void)drawRect:(CGRect)rect {
CGRect b = self.bounds;
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGFloat columnWidth = b.size.width / columnCount;
CGFloat rowHeight = b.size.height / rowCount;

for (NSUInteger rowIndex = 0; rowIndex < rowCount; rowIndex++) {
  for (NSUInteger columnIndex = 0; columnIndex < columnCount; columnIndex++) {
    NSUInteger colorIndex = rowIndex * columnCount + columnIndex;
    UIColor *color = [self.colors count] > colorIndex ? [self.colors objectAtIndex:colorIndex] : [UIColor whiteColor];
      CGRect r = CGRectMake(b.origin.x + columnIndex * columnWidth,
                        b.origin.y + rowIndex * rowHeight,
                        columnWidth, rowHeight);
    CGContextSetFillColorWithColor(myContext, color.CGColor);
    CGContextFillRect(myContext, r);


  }
 }
}

I know I will not need certain things like the color or the CGContextSetFillColorWithColor line, but how do i replace myContent with the image, it seems like this is what I would have to do, but I have not been able to successfully do this. Thanks again for your help as I am newer to Objective C.

  • 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-12T17:41:02+00:00Added an answer on June 12, 2026 at 5:41 pm

    Assuming that you want to continue to do drawing into the view using drawRect:, I think you just want to use the drawInRect: method on UIImage.

    So:

    UIImage *image = [plays objectAtIndex:rowIndex * columnCount + columnIndex];
    [image drawInRect:r];
    

    I’ve heard the performance of drawInRect is not great – but I haven’t measured it myself. Note also that drawInRect: scales the image to fit the rect as needed; so visually, the results may not be what you intend.

    An alternative is to compose your popover’s view in a nib where you could layout your view statically. If you always want a 2×3 matrix, you could setup your view there with a 2×3 grid of UIImageView instances.

    EDIT: (to clarify that you are drawing images in the rects now, no filling blocks of color)

    - (void)drawRect:(CGRect)rect {
        CGRect b = self.bounds;
        CGContextRef myContext = UIGraphicsGetCurrentContext();
        CGFloat columnWidth = b.size.width / columnCount;
        CGFloat rowHeight = b.size.height / rowCount;
    
        for (NSUInteger rowIndex = 0; rowIndex < rowCount; rowIndex++) {
            for (NSUInteger columnIndex = 0; columnIndex < columnCount; columnIndex++) {
                CGRect r = CGRectMake(b.origin.x + columnIndex * columnWidth,
                            b.origin.y + rowIndex * rowHeight,
                            columnWidth, rowHeight);
                UIImage *image = [plays objectAtIndex:rowIndex * columnCount + columnIndex];
                [image drawInRect:r];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my console application have an abstract Factory class Listener which contains code for
I have following models setup in my Django application class School(models.Model): name = models.TextField()
In my application I have a class which has properties of user-defined types like
in my zf application i have base model class Application_Model, which connects to db
In a C# Winforms (3.5) application I have added a class that contains many
I have a .NET application. When I obfuscated the assembly, namespace, class name and
in my Silverlight 4 application, I have a class myClass that contains a list
In my web application I have around 10 headings with same class name, so
In my Android application, I have a DefaultApplication class which extends android.app.Application , and
In a client application I have a DBIx::Class model 'Todo' that can be linked

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.