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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:15:11+00:00 2026-06-08T07:15:11+00:00

I am trying to create a grid UIScrollView , which so far is working

  • 0

I am trying to create a grid UIScrollView, which so far is working great, I am just having a little trouble with adding 20px padding to both the width and height of the UIImageViews being displayed in the `UIScrollView“.

At the moment, I am adding 20px (px & py) to both the x and y values of the UIImageView’s frame. However, this just moves the rows along 20px, and the columns down 20px. Please can you tell me where I am going wrong?

int x = 0;
int y = 0;
int w = 65;
int h = 65;
int c = 0;
int r = 0;
int px = 20;
int py = 20;

for (int i = 0; i < [self.content count]; i++) {

    if (c < 4)
        c++;
    else if (c == 4) {
        c = 0;
        r++;
    }

    x = c * w;

    y = r * h;

    x += px;

    y += py;

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];

    [imageView setImage:[self.content objectAtIndex:i]];

    [imageView setContentMode:UIViewContentModeScaleToFill];

    [self.scrollView addSubview:imageView];

    [imageView release];

}
  • 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-08T07:15:12+00:00Added an answer on June 8, 2026 at 7:15 am

    You want the padding between each image, right? As it stands, you’re basically only adding it in once, at the very top. Instead, add the padding, then multiply by the row and column. Each image should be spaced out then.

    EDIT to correct a silly mistake on my part.

    x = c * (w + px);
    y = r * (h + py);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create some kind of grid layout with css: Having a content
I am trying to create a grid of thumbnails in wordpress, which I've managed
I'm trying to create a tabbed panel having a different jquery grid in each
I am trying to create a grid like system with div's with content floated
I'm trying to create a dynamic grid using ExtJS. The grid is built and
I am trying to create a 5x5 grid with 2 exits and put some
What I'm trying to do: Create a 'grid' once the page loads with some
I am trying to create a simple ajax grid that allows me to add
I'm trying to create a page that contains a grid and searching. The issue
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can

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.