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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:46:37+00:00 2026-05-21T07:46:37+00:00

I need to create a a bunch a views on the fly. I was

  • 0

I need to create a a bunch a views on the fly. I was wondering what would be the best way to go about doing this as ill need to define coordinates, tag, colours of each view.

Would i need to create a multidimensional array and if so how can i do this?

CGRect viewRect1 = { 80.0, 200.0, 160.0, 100.0 };
UIview *myview1 = [[UIview alloc] initWithFrame:viewRect1];
[myview1 setBackgroundColor:[UIColor darkGrayColor]];
  • 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-05-21T07:46:37+00:00Added an answer on May 21, 2026 at 7:46 am

    You need to define a structure to hold the data which is needed to create your UIView.

    @interface MyViewDataHolder :NSObject
    {
         CGRect mViewRect;
         UIColor* mDarkGrayColor;
         NSInterger mTag;
    }
    
    @end
    

    Then create an object of above class AND assign the values in member then add that in your NSArray…

    EDITED:

    In MyViewDataHolder.h class

    @interface MyViewDataHolder :NSObject
    {
        CGRect mViewRect;
        UIColor* mDarkGrayColor;
        NSInteger mTag;
    }
    @property (nonatomic,assign) CGRect mViewRect;
    @property (nonatomic,retain) UIColor* mDarkGrayColor;
    @property (nonatomic,assign) NSInteger mTag;
    
    @end
    

    In MyViewDataHolder.mm class

    #import "MyViewDataHolder.h"
    
    
    @implementation MyViewDataHolder
    
    @synthesize mViewRect,mDarkGrayColor,mTag;
    
    -(void) dealloc
    {
        [mDarkGrayColor release]
        mDarkGrayColor = nil;
    }
    

    Now How to use it ….

    Create objects of MyViewDataHolder like below …

    MyViewDataHolder* myObj1 = [[MyViewDataHolder alloc] init];
    myObj1.mViewRect = CGRectMake(x,y,width,height);
    myObj1.tag = 1;
    myObj1.mDarkGrayColor = [UIColor redColor];
    

    Create as much as you need

    Then Create an NSMutableArray and add each objects of MyViewDataHolder into NSMutableArray.

    NSMutableArray* myArray = [[NSMutableArray alloc] init];
    [myArray addObject:myObj1];
    [myArray addObject:myObj2];
    [myArray addObject:myObj3];
    and So on ....
    

    When you need the stored info you could use as below …

    for(int index =0; index < [myArray count]; index++)
    {
    
         MyViewDataHolder* myObj = (MyViewDataHolder*)[myArray objectAtIndex:index];
         myView = [[UIView alloc] initWithFrame:myObj.mViewRect];
         //incriment x and y to refelect where you want your next view to be suituated 
         myView.tag = myObj.mTag; 
         myView.backgroundColor =  myObj.mDarkGrayColor;
         [self.view addSubview:myView];
         [myView release];
    }
    

    The code reflect the approach , Although I didn’t compile the code So use it as reference

    Thanks ,

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

Sidebar

Related Questions

Ok, I'm doing a bunch of RIA/AJAX stuff and need to create a pretty,
i need create an email list sending to many emails. what is best solution
I need to create a bunch of timer as local variable to do something
ok i am given a bunch of leafs 10,9,7,8 and i need to create
I need create custom dialog and put JPanel into it. Is it possible?
I need create clone repository. but I do not know where can I get
I need create a document word with Java. And I ask, how can I
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass
I have dynamically created WrapPanel (_wp) with several Borders. And I need create handler
Need to create a custom DNS name server using C which will check against

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.