UIButtons from different views add images to same view?
So, I am building an application with different views. Each of them has a number of buttons. When pressing a button in a view, it should add an image to a addedImages view (the main one). How do I make a loop that will add the images dynamically according to t开发者_Python百科he position of previously added images? Im quite new in this, so now I have only one button adding an image like this:
- (IBAction)addItemToShoppingList
{
UIImage *image = [UIImage imageNamed:@"button1.jpg"];
UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
imageView.frame = CGRectMake(120, 100, 80, 80);
[shoppingList.view addSubview:imageView];
[imageView release];
}
So I wanna make a function addItemToShoppingList that will be associated to all buttons in different views but to put different images dynamically to the same one?
int shoppingListX;
- (IBAction)addItemToShoppingList
{
UIImage *image = [UIImage imageNamed:@"button1.jpg"];
UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
imageView.frame = CGRectMake(shoppingListX, 100, 80, 80);
shoppingListX += 80;
[shoppingList.view addSubview:imageView];
[imageView release];
}
精彩评论