我是目标c的新手。我需要在基于UIView的应用程序中添加facebook like button。对于这种情况,我创建了一个操作按钮并写下以下代码:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 460.0)];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString *htmlString = [NSString stringWithFormat:@"<html>\
<body style=\"color: #000000; font-family: Helvetica; font-size: 10pt;\">\
<tr>\
<td colspan=2>\
<a style=\"color: #000000; font-family: Helvetica; font-size: 10pt; width:50px; height:20px;\" href=https://www.facebook.com/abc..><img src=\"facebook_like.png\" width=50 height=50 style=\"float:left; \" /></a><br>\
</td>\
</tr>\
</body>\
</html>"];
[webView loadHTMLString:htmlString baseURL:baseURL];
但是当我点击动作按钮时,它不起作用。
答案 0 :(得分:1)
Facebook没有在他们的SDK中提供这个,但有一个名为FacebookLikeView的开源Github项目,您可以使用或检查它们是如何做到的。
答案 1 :(得分:0)
您可以使用UIButton。我不确定你想要完成什么。
UIButton *btn = [UIButton buttonWithType: UIButtonTypeCustom];
btn.frame = CGRectMake(0.0, 0.0, 320.0, 460.0);
[btn setImage:[UIImage imageNamed:@"facebook_like.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonPushed:) forControlEvents:UIControlEventTouchUpInside];
希望这可以提供帮助。不要忘记将 - buttonPushed:(id)发送者添加到该类。就此而言,将其添加到您的视图中。