[英]Change FBProfilePictureView with an UIImageView(or load an UIImage) Swift
[英]Turn FBProfilePictureView into UIImage
我有一個Facebook登錄名,可獲取用戶profilePicture,lblUsername和lblEmail 。 我知道FBProfilePictureView是一個包含UIImageView的UIView。
所以,我要問的是如何轉換或“保存”從Facebook獲得的profilePicture作為UIImage? 這是我的LoginViewController.m 。 我已經在LoginViewController.h文件中正確導入了Facebook SDK。
#import "LoginViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface LoginViewController ()
- (void)toggleHiddenState:(BOOL)shouldHide;
@end
@implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self toggleHiddenState:YES];
self.lblLoginStatus.text = @"";
self.loginButton.readPermissions = @[@"public_profile", @"email"];
self.loginButton.layer.cornerRadius = 0;
[self.loginButton.layer setBorderWidth:0.0f];
self.loginButton.delegate = self;
// UIImageView *image = nil;
//
// for (NSObject *pic in [self.profilePicture subviews]) {
// if ([pic isMemberOfClass:[UIImageView class]]) {
// UIImageView *objImg = (UIImageView *)pic;
// image = objImg.image;
// break;
// }
// }
//
// self.view.backgroundColor = [UIColor colorWithPatternImage:image];
//
// Do any additional setup after loading the view.
}
-(void)toggleHiddenState:(BOOL)shouldHide{
self.lblUsername.hidden = shouldHide;
self.lblEmail.hidden = shouldHide;
self.profilePicture.hidden = shouldHide;
self.loggedinwallpaper.hidden = shouldHide;
self.FBlogout.hidden = shouldHide;
}
-(void)toggleUnhiddenState:(BOOL)shouldShow{
self.loggedinwallpaper.hidden = NO;
}
-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"";
[self toggleHiddenState:NO];
[self toggleUnhiddenState:YES];
}
-(void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"";
[self toggleHiddenState:YES];
}
-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
NSLog(@"%@", user);
self.profilePicture.profileID = user.objectID;
self.lblUsername.text = user.name;
self.lblEmail.text = [user objectForKey:@"email"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *homeViewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
[self presentViewController:homeViewController animated:YES completion:nil];
//
// for (NSObject *obj in [self.profilePicture subviews]) {
// if ([obj isMemberOfClass:[UIImageView class]]) {
// UIImageView *objImg = (UIImageView *)obj;
// image = objImg.image;
// break;
// }
// }
}
-(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{
NSLog(@"%@", [error localizedDescription]);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// UIImage *image = _profilePicture;
// HomeViewController *homeviewController = (HomeViewController *)segue.destinationViewController;
// homeviewController.homepic = image;
//
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
//}
@end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.