2010-07-11 37 views
0
CGRect frame = CGRectMake(10.0, 30.0, 32.0, 29.0); 
UIImage *buttonImage = [UIImage imageNamed:@"visit_icon.png"]; 
UIButton *stopButton = [[UIButton alloc] initWithFrame:frame]; 
[stopButton setTitle:@"Button" forState:UIControlStateNormal]; 
[stopButton setTitleColor:[UIColor blackColor] forState:UIControlEventTouchDown]; 
[stopButton setBackgroundImage:buttonImage forState:UIControlStateNormal]; 
stopButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
stopButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 
[stopButton addTarget:self action:@selector(stopAction:) forControlEvents:UIControlEventTouchUpInside]; 

我正在添加按鈕到我的根視圖控制器不工作 可能我需要添加這個作爲我的觀點的子視圖 我該怎麼做?以編程方式添加按鈕在導航根視圖中不起作用爲什麼?

回答

0

你在正確的軌道上。

UIViewController子爲此,在你的代碼的結尾上面:

[self.view addSubview: stopButton]; 
+0

是的,但我怎麼能在底部標籤欄 – 2010-07-11 11:57:05

+0

添加按鈕,我怎樣才能把我的主視圖中的圖像添加作爲以前的子視圖... – 2010-07-11 16:38:10

+0

'[stopButton removeFromSuperview];' – 2010-07-11 22:41:49

相關問題