如何在 Xcode 上按高度调整 Facebook 个人资料图片的大小?
Posted
技术标签:
【中文标题】如何在 Xcode 上按高度调整 Facebook 个人资料图片的大小?【英文标题】:How to resize Facebook Profile Picture by height on Xcode? 【发布时间】:2013-05-16 08:28:18 【问题描述】:如何使用 WIDTH: AUTO & HEIGHT: x amount 调整 Facebook 头像的大小?下面的代码有效,但是当头像更宽时,图像看起来很狭窄。
/**
* 更新头像 */ -(无效)handleAvatar if ([[个人账号] 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];
【问题讨论】:
【参考方案1】:通过指定 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);
];
【讨论】:
以上是关于如何在 Xcode 上按高度调整 Facebook 个人资料图片的大小?的主要内容,如果未能解决你的问题,请参考以下文章
SWIFT - 改变 UITextView 的高度,xcode 6 GM
SWIFT - 改变 UITextView 的高度,xcode 6 GM