在圈子视图中加载Facebook个人资料图片 - bug

时间:2014-08-22 09:38:50

标签: ios objective-c iphone ios7

我是iOS新手,我遇到了问题。我使用parse.com作为我的后端,我有一个错误加载我的Facebook个人资料img。我想将图片添加到UIImage视图中并使视图成为圆形。我使用URLrequest https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1下载图像,然后将图像放入imageData。有没有任何教程如何实现这一目标?我希望它像http://ewebdesign.com/wp-content/uploads/2013/11/110.jpg //个人资料图片。谢谢你的帮助。

5 个答案:

答案 0 :(得分:1)

所有答案都是真的!
他们唯一错过的是图片的宽度必须等于高度,即 它必须是平方的,否则你的图像将像椭圆形。 因此,获得具有相同宽度和高度的轮廓图像,例如 https://graph.facebook.com/%@/picture?type=square&width=120&height=120

答案 1 :(得分:0)

QuartzCore.framework导入项目,将UIImageView layer.cornerRadius设置为所需的值,并设置layer.masksToBounds = YES;以获得圆形图像视图。

#import <QuartzCore/QuartzCore.h>
yourImageView.layer.cornerRadius = yourImageView..size.height/ 2;
yourImageView.layer.masksToBounds = YES;

答案 2 :(得分:0)

尝试这个  

UIImage *image = //Image from API
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.layer.cornerRadius = image.size.width / 2;
imageView.layer.masksToBounds = YES;
[self.view addSubview: imageView];

答案 3 :(得分:0)

这里是从Facebook下载图片的代码:

// Specify link parameters
NSMutableString *link = [NSMutableString stringWithString:@"https://graph.facebook.com/"];
[link appendFormat:@"%@/picture", userId];
[link appendFormat:@"?height=%d&width=%d", pictureHeight, pictureWidth];

// Send request to load image
NSURL *requestURL = [NSURL URLWithString:link];
NSMutableURLRequest *pictureRequest = [NSMutableURLRequest requestWithURL:requestURL];

[NSURLConnection sendAsynchronousRequest:pictureRequest
                                   queue:[NSOperationQueue mainQueue]
                       completionHandler:
 ^(NSURLResponse *response, NSData *data, NSError *connectionError) {

   if (connectionError) {

     // Process error;
   } else {

     UIImage *picture = [UIImage imageWithData:data scale:scale];
     return picture;
   }
 }

答案 4 :(得分:0)

尝试使用FBProfilePictureView作为项目,这是示例项目facebook-ios-sdk

如何设置圆圈视图,

1)添加#import <QuartzCore/QuartzCore.h>

2)FBProfilePictureView类的设置值:

profilePic.layer.masksToBounds = YES;
profilePic.layer.cornerRadius = 30.0;

希望能帮到你。