How can I convert FBProfilePictureView to an UIImage?

前端 未结 4 760
遥遥无期
遥遥无期 2020-12-03 05:18

Everything is working fine with FBProfilePictureView but I need to get that picture from FBProfilePictureView and turn it into an UIImage.

How should I do it?

4条回答
  •  时光取名叫无心
    2020-12-03 06:08

    I have found above solutions to be quite working but here is updated code which i found it more easy going.

     @property FBSDKProfilePictureView *pictureView;
    
     if ([FBSDKAccessToken currentAccessToken]) {
    
    
        self.pictureView=[[FBSDKProfilePictureView alloc]init];
    
        [self.pictureView setProfileID:@"me"];
        [self.pictureView setPreservesSuperviewLayoutMargins:YES];
        [self.pictureView setPictureMode:FBSDKProfilePictureModeNormal];
        [self.pictureView setNeedsImageUpdate];
        [self performSelector:@selector(getUserImageFromFBView) withObject:nil afterDelay:1.0];
    
    }
    
    -(void) getUserImageFromFBView
    {
    UIImage *image = nil;
    
    for (NSObject *obj in [self.pictureView subviews]) {
        if ([obj isMemberOfClass:[UIImageView class]]) {
            UIImageView *objImg = (UIImageView *)obj;
            image = objImg.image;
            break;
        }
    }
    [self.profilePic setImage:image forState:UIControlStateNormal];
    }
    

    Hope this helps. Here i have put 1 second delay to wait for the profile picture to load.

提交回复
热议问题