johannix
johannix

Reputation: 29658

iOS dynamic addition of UIControls

I'm trying to add a bunch of UIButtons to a screen at runtime. Based on user input I want to show different buttons in different locations. Is this possible?

Upvotes: 1

Views: 218

Answers (1)

brimat
brimat

Reputation: 166

Yes, it's possible.

Creating a button in objective-C:

UIButton *btnPrefix = [UIButton buttonWithType:UIButtonTypeCustom];
[btnPrefix setFrame:CGRectMake(0, 0, 20, 20)];
[btnPrefix setUserInteractionEnabled: YES];
[btnPrefix addTarget:self action:@selector(buttonTapped) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: btnPrefix];

Upvotes: 2

Related Questions