Ashish
Ashish

Reputation: 207

how to add facebook like button in my UIView based iphone application?

i am new in objective c. I need to add facebook like button in my UIView based application. For this case i have create a action button and write bellow code:

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];

But when i click on action button it does not work.

Upvotes: 0

Views: 1380

Answers (2)

Zach Howe
Zach Howe

Reputation: 26

You could use UIButton. I'm not exactly sure what youre trying to accomplish though.

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];

Hopefully this can help. Don't forget to add - buttonPushed:(id)sender to that class. And for that matter, add it to your view.

Upvotes: 0

coneybeare
coneybeare

Reputation: 33101

Facebook has not provided this in their SDK, but there is an open-source Github project called FacebookLikeView that you can either use or inspect to see how they did it.

Upvotes: 1

Related Questions