How do I resize Facebook avatar with WIDTH: AUTO & HEIGHT: x amount ? Code below works but when the avatar is wider, it appears that the image is cramped.

/**

* Update avatar */ - (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];
}

}

有帮助吗?

解决方案

Fixed by specifying width and height of FBRequestConnection Parameters.

    /**
 * 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);
                                      }
                                  }];
        }
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top