2011-05-03 59 views
-1

我已经设法通过代码在Xcode中创建了一个简单的四舍五入矩形按钮,但我实际上有点麻烦让它做更多我想要的。Progammatically Create Button to URL

理想的情况是一个自定义按钮类型与图像在这两个国家image.png链接到一个URL(比如说www.google.com)任何人都可以帮我吗?我想我需要写一个方法来做链接。那我可以处理,只是不知道如何把它挂无接口生成器(靶向iOS版)

现有代码

  UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [btn addTarget:self action:@selector(supporturl) forControlEvents:UIControlEventTouchDown]; 
     btn.frame = CGRectMake(20, 20, 150, 50); 
     [btn setTitle:@"Support and Help" forState:UIControlStateNormal]; 
     [self addSubview:btn]; 
+0

哎呀对不起,没”我意识到我错过了! iOS版。 – David26th 2011-05-03 07:32:42

回答

1
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20.0f, 20.0f, 150.0f, 50.0f)]; 
[btn setTitle:@"Support and Help" forState:UIControlStateNormal]; 
[btn setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal]; 
[btn addTarget:self action:@selector(openWebPage) forControlEvents:UIControlEventTouchUpInside]; 
[self.view addSubview:btn]; 
[btn release]; 

,并在功能上

-(void) openWebPage 
{ 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]]; 
}