iPhone Dev - Create UIButton Manually

后端 未结 1 1037
执念已碎
执念已碎 2020-12-24 01:56

I\'m learning how to develop on the iPhone, I bought a book called Beginning iPhone 3 development Exploring the SDK. After I bit I decided to ditch Interface Builder. I stil

1条回答
  •  离开以前
    2020-12-24 02:31

    I'd try something like this:

        UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        myButton.frame = CGRectMake(20, 20, 200, 44); // position in the parent view and set the size of the button
        [myButton setTitle:@"Click Me!" forState:UIControlStateNormal];
        // add targets and actions
        [myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        // add to a view
        [superView addSubview:myButton];
    

    Disclaimer: Just typing this in here. I don't have access to my Mac at the moment so I can't test it.

    P.S. Any particular reason not to use Interface Builder? Just curious.

    0 讨论(0)
提交回复
热议问题