如何使用WIDTH调整Facebook头像的大小:AUTO&身高:x金额?下面的代码有效,但当化身更宽时,图像看起来很狭窄。
/**
*更新头像 * / - (void)handleAvatar { if([[self account] getAvatar]){ if(![self avatarDrawn]){ [self.avatarImageView setHidden:NO];
[ApiGateway avatarImage: [self account]
completionHandler: ^(UIImage *fetchedImage, NSURL *fetchedURL, BOOL isInCache) {
UIImage * roundedImage = [UIImage roundImage:[UIImage imageWithImage:fetchedImage scaledToSize:self.avatarImageView.frame.size] borderWidth:7.0f];
[[self avatarImageView] setImage:roundedImage];
[self setAvatarDrawn:YES];
/**
@todo Remove strange thin border
*/
} errorHandler:^(NSError *error) {
[Util showNetworkError:error];
}];
}
} else {
[self.avatarImageView setHidden:YES];
}
}
答案 0 :(得分:0)
通过指定FBRequestConnection参数的宽度和高度来修复。
/**
* Try to fetch an avatar
*/
- (void) sessionStateChanged:(NSNotification*)notification {
if ([[self account] useFacebookAuthentication]){
// Try and fetch an avatar
if ([[FBSession activeSession] isOpen]) {
// First up, get the facebook User data
[FBRequestConnection startWithGraphPath: @"me"
parameters: [NSDictionary dictionaryWithObject: @"picture.width(200).height(200)" forKey: @"fields"]
HTTPMethod: @"GET"
completionHandler: ^(FBRequestConnection *connection, id<FBGraphUser> fbuser, NSError *error) {
if (!error) {
// Set Avatar to account
[[self account] setAvatar:[fbuser objectForKey:@"picture"][@"data"][@"url"]];
// Update cell
NSIndexPath *mypath = [NSIndexPath indexPathForRow:0 inSection:0];
DashboardCell *cell = (DashboardCell *)[[self tableView] cellForRowAtIndexPath:mypath];
[cell updateUI];
} else {
NSLog(@"FB error %@", error);
}
}];
}
}
}