Karthick
Karthick

Reputation: 382

creating new UIView objects from XIB

I have a view created in xib with UIImageviews and UILabel as the subviews. From my code, is it possible to create a new view object every time i run a loop.Please help me.

Upvotes: 2

Views: 1148

Answers (2)

BarryK88
BarryK88

Reputation: 1806

When you have created a view and hooked it up via interface builder you can easily add views like

for(int i = 0; i < numberOfIterations; i++){
     UIView * newView = [[UIView alloc] initWithFrame:MyFrame];
     [myInterfaceBuilderView addSubview:newView];
}

Upvotes: 0

LE SANG
LE SANG

Reputation: 11005

You need to create a new custom view named CustomView Select class in XIB to CustomView.

Then load XIB name to a View object and can use in a loop

CustomView *aView = [[[NSBundle mainBundle] loadNibNamed:@"YourXibName" owner:nil options:nil] objectAtIndex:0];

Upvotes: 4

Related Questions