ios从图像链接到页面

时间:2014-07-24 08:50:42

标签: ios image anchor

我真的想知道如何在iOS应用程序中为图像添加锚点。锚点指向某个页面。

在网上看起来像这样:

<a href="www.somepage.com"><img src="myimage.jpg"/></a>

感谢

2 个答案:

答案 0 :(得分:2)

-(void)foo
{
...
    UIButton *btn = [[UIButton alloc] initWithFrame:frame];
    [btn setBackgroundImage:[UIImage imageNamed:@"myimage.jpg"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
...
}

-(void)btnPressed:(UIButton*)sender {

        NSURL *url = [NSURL URLWithString:@"http://www.nba.com"];

        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
        }

}

答案 1 :(得分:1)

.....

UIButton *btn = [[UIButton alloc] initWithFrame:frame];
[btn setBackgroundImage:[UIImage imageNamed:@"myimage.jpg"] forState:UIControlStateNormal];
[btn addTarget: action:@selector(btnPressedToOpenUrl) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];

-(void)btnPressedToOpenUrl
{
UIWebView *webView=[[UIWebView alloc]initWithFrame:frame];
 NSURL * url = [NSURL URLWithString:@"https://www.somepage.com" ];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
[self.view addSubview:webView];
}
相关问题