【问题标题】:Get an image from FBProfilePictureView swift快速从 FBProfilePictureView 获取图像
【发布时间】:2015-03-11 03:14:25
【问题描述】:

fb登录时,如下UIView显示用户头像

@IBOutlet var profilePictureView : FBProfilePictureView

如何获取图像以便可以在其他地方使用/保存到服务器?

这是关于 FBProfilePictureView 的 fb 文档(在 Objective-C 中)https://developers.facebook.com/docs/reference/ios/current/class/FBProfilePictureView 这是fb登录的快速端口,效果很好。 https://www.snip2code.com/Snippet/68653/This-is-a-swift-port-of-the-official-Fac 这是相同的代码,但在目标 C 中 How can I convert FBProfilePictureView to an UIImage?

【问题讨论】:

    标签: ios facebook swift


    【解决方案1】:

    你也可以使用其他的想法,

    Objective-C

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

    也改变类型

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

    斯威夫特

     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?
    【解决方案2】:

    正如您链接到 (https://stackoverflow.com/a/12479572/2274694) 的答案中所解释的,您可以像对待任何 UIView 一样对待 FBProfilePictureView 并遍历子视图以找到 UIImageView 并访问图像:

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

    【讨论】:

      猜你喜欢
      • 2016-03-03
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多