Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从FBProfilePictureView swift获取图像_Ios_Facebook_Swift - Fatal编程技术网

Ios 从FBProfilePictureView swift获取图像

Ios 从FBProfilePictureView swift获取图像,ios,facebook,swift,Ios,Facebook,Swift,使用fb登录时,以下UIView显示用户配置文件图片 @IBOutlet var profilePictureView : FBProfilePictureView 如何获取图像以便在其他地方使用/将其保存到服务器 以下是FBProfilePictureView上的fb文档(在Objective-C中) 这里是fb登录的swift端口,它运行良好。 这是相同的代码,但在目标C中 如您链接到()的答案中所述,您可以像对待任何ui视图一样对待FBProfilePictureView,并遍历子视图,

使用fb登录时,以下UIView显示用户配置文件图片

@IBOutlet var profilePictureView : FBProfilePictureView
如何获取图像以便在其他地方使用/将其保存到服务器

以下是FBProfilePictureView上的fb文档(在Objective-C中) 这里是fb登录的swift端口,它运行良好。 这是相同的代码,但在目标C中

如您链接到()的答案中所述,您可以像对待任何
ui视图一样对待
FBProfilePictureView
,并遍历子视图,以找到
UIImageView
并访问图像:

var image:UIImage!

for obj in profilePictureView.subviews {
    if obj is UIImageView {
        let objImg = obj as UIImageView
        image = objImg.image
        break
    }
}

你也可以用另一种方法

目标-C

 NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [FBuser objectID]];
同时更改类型

  • 类型:小型、普通、大型、方形
Swift

 let avatar = "https://graph.facebook.com/\(user.objectID)/picture?width=640&height=640"
还是另一种选择

let url = NSURL.URLWithString("https://graph.facebook.com/\(user.objectID)/picture?width=640&height=640");
let data = NSData(contentsOfURL: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check
yourimagename.image = UIImage(data: data!)

如何将此字符串转换为UIImage?