Skip to content

Instantly share code, notes, and snippets.

@rajiv-singaseni
Created December 15, 2011 14:17
Show Gist options
  • Save rajiv-singaseni/1481232 to your computer and use it in GitHub Desktop.
Save rajiv-singaseni/1481232 to your computer and use it in GitHub Desktop.
Updated facebook like update labels function.
-(void) updateLabels {
int remaining = totalLikesCount - friendsLikesCount - (userLikesPage?1:0);
NSString *string;
if (remaining == 0) {
if (!userLikesPage && friendsLikesCount == 0) {
string = @"Be the first to like this.";
} else if (userLikesPage && friendsLikesCount == 0) {
string = @"You like this.";
} else if (userLikesPage && friendsLikesCount > 0) {
string = [NSString stringWithFormat:@"You and %d %@ like this.",friendsLikesCount, (friendsLikesCount > 1? @"friends": @"friend")];
} else {
string = [NSString stringWithFormat:@"%d %@ like this.", (friendsLikesCount > 1? @"friends": @"friend")];
}
} else { // remaining > 0
if (!userLikesPage && friendsLikesCount == 0) {
string = [NSString stringWithFormat:@"%d like this.",remaining];
} else if (userLikesPage && friendsLikesCount == 0) {
string = [NSString stringWithFormat:@"You and %d others also like this.", remaining];
} else if (userLikesPage && friendsLikesCount > 0) {
string = [NSString stringWithFormat:@"You, %d %@ and %d others also like this.",friendsLikesCount, (friendsLikesCount > 1? @"friends": @"friend"), remaining];
} else {
string = [NSString stringWithFormat:@"%d %@ and %d others also like this.",friendsLikesCount, (friendsLikesCount > 1? @"friends": @"friend"), remaining];
}
}
if (totalCheckinsCount > 0) {
string = [string stringByAppendingFormat:@" %d were here.",totalCheckinsCount];
}
self.likeDescription.text = string;
self.likeButton.hidden = userLikesPage;
if (userLikesPage) {
likeDescription.frame = CGRectUnion(likeDescription.frame, likeButton.frame);
buttonDescription.text = @"";
likeDescription.frame = CGRectUnion(likeDescription.frame, buttonDescription.frame);
} else {
buttonDescription.text = PRE_LIKE_TEXT;
}
[self setNeedsDisplay];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment