sourik datta
sourik datta

Reputation: 15

Want to add Controls at Runtime in IPhone Application C#, Monotouch

I have a TabViewController. It consists of several views. For a particular view I want to add some buttons dynamically at runtime. The view already have some controls which has been created using Interface Builder.

Upvotes: 0

Views: 1665

Answers (2)

Waescher
Waescher

Reputation: 5737

You can add controls like this:

    // create new control
    var control = new UIView(); // or UIButton, etc.

    // set control props ..
    control.Hidden = false;
    control.Frame = x // = Bounds
    // ...

    // add control to parent
    window.AddSubview(control);

Upvotes: 1

Janak Nirmal
Janak Nirmal

Reputation: 22726

just sample code for UIButton

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[yourView addSubview:button];

Here you can set Button Type/Controlling Event/Title etc as per your requirement.

Hope this helps.

Upvotes: 0

Related Questions