2011-01-24 73 views
5

在我的iPhone應用程序中,如何以編程方式在uiview中添加下一個和上一個按鈕?如何在iphone中以編程方式在uiview中創建按鈕

+2

可我知道什麼是這個答案的問題,建立動態按鈕? http://stackoverflow.com/questions/4778491/how-to-add-next-and-previous-buttons-programmaticaly-in-iphone/4778594#4778594 – KingofBliss 2011-01-24 06:38:12

+0

可能的重複[如何在iPhone中以編程方式添加下一個和上一個按鈕?](https://stackoverflow.com/questions/4778491/how-to-add-next-and-previous-buttons-programmatically-in-iphone) – 2017-11-21 08:47:06

回答

16

您可以用下面的代碼

UIButton *but=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    but.frame= CGRectMake(200, 15, 15, 15); 
    [but setTitle:@"Ok" forState:UIControlStateNormal]; 
    [but addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside]; 
    [self.view addSubview:but]; 
相關問題