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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:20:16+00:00 2026-06-07T13:20:16+00:00

I have created a main View and in that I add 9 UIMyView that

  • 0

I have created a main View and in that I add 9 UIMyView that I subclassed from UIView.
I add instances of that UIMyViews using NSBundle to load the nib file and addSubview in the main view controller, of course all of these views are appeared in the upper left corner of the super view one hiding the other and the last one to be visible, which either I need to position them somehow using points in super view or create something like a table and add to its cells the UIMyViews?!

Imagine you have a table and put 9 deck cards positioned 3 rows and 3 columns (9 cards).
This is what I need to achieve.

[EDIT]
Check this image: http://www.wpclipart.com/recreation/games/card_deck/cards_symbols/playing_card_symbols.png

I just need 3 rows and 3 columns.

Anyone can suggest best practice for this kind of operation?

Afterwards just to have in mind I want to implement various animations and effects on these UIMyViews while draged, touched and reordering etc.

Thank you.

  • 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-07T13:20:18+00:00Added an answer on June 7, 2026 at 1:20 pm

    If you want to loop through all the views and position them in a grid, you can so like this:

        // Array of 9 views    
    NSArray *views = [NSArray arrayWithObjects:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], nil];
    
    int count = 0;
    int maxPerRow = 3;
    int row = 0;
    float spacing = 100.0;
    
    for(UIView *view in views)
    {
        // Only added to tell the difference between views, make sure to import QuartzCore or remove the next 3 lines
        view.backgroundColor = [UIColor colorWithRed:.5 green:0 blue:0 alpha:1];
        view.layer.borderWidth = 1;
        view.layer.borderColor = [UIColor whiteColor].CGColor;
    
        // position view
        view.frame = CGRectMake(count*spacing, row * spacing, view.frame.size.width, view.frame.size.height);
        [self.view addSubview:view];
    
        if(count % maxPerRow == maxPerRow-1)
        {
            count = 0;
            row++;
        }
        else
        {
            count++;
        }
    }
    

    That will give you something like this:

    enter image description here

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

Sidebar

Related Questions

the main tableview will have rows that is added/created from the user and that
I have created a piece of code which takes an IP address (from main
I have created a list form that gets attached to a main form in
I have created a JApplet using the JUNG library in Netbeans that compiles and
I have created an array Man: public main blah blah{ man = man[10]; }
I have created a very simple GUI project in Qt as follows: main: #include
I have created a MY_Controller and I'm linking to it through my main controller...
I have a Main class and a HelloWorld class. I have created a button
Hey Guys, i have created the following Menu Structure: <div id=menu> <ul> <li><a href=#>Main
I have some BitmapFrames created on a thread other than the main UI thread;

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.