UIButton没有出现在viewController上

时间:2011-04-08 10:20:03

标签: iphone ios ipad

嘿我试图在ipad上渲染模态视图,就像这样。

login_manager *log = [[login_manager alloc]init];

UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:log];

nav.modalPresentationStyle = UIModalPresentationFormSheet;

[self presentModalViewController:nav animated:YES];

[log release]`

然后在viewDidLoad中添加一个按钮。

-(void)viewDidLoad{

UIButton *facebook = [UIButton buttonWithType:UIButtonTypeCustom];

facebook.frame = CGRectMake(10,10,402,68);

facebook.imageView.image = [UIImage imageNamed:@"loginFB.png"];

[facebook addTarget:self action:@selector(login_FB) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:facebook];}

但是我不能让按钮出现在屏幕上,图像链接正确并且正在调用viewDidLoad,但没有弹出任何内容。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

(void)viewDidLoad

{

UIButton *facebook = [UIButton buttonWithType:UIButtonTypeCustom];

facebook.frame = CGRectMake(10,10,402,68);

[facebook setImage:[UIImage imageNamed:@"loginFB.png"] forState:UIControllStateNormal];

[facebook addTarget:self action:@selector(login_FB) 

forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:facebook];

}

答案 1 :(得分:2)

-(void)viewDidLoad{    
UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[sampleButton setFrame:CGRectMake(10, 10, 200, 52)];
[sampleButton setTitle:@"Button Title" forState:UIControlStateNormal];
[sampleButton setBackgroundImage:[[UIImage imageNamed:@"loginFB.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[sampleButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:sampleButton];
}