Skip to content

Instantly share code, notes, and snippets.

@erichsu
Created October 4, 2015 03:09
Show Gist options
  • Save erichsu/35cf566d0836166a7a03 to your computer and use it in GitHub Desktop.
Save erichsu/35cf566d0836166a7a03 to your computer and use it in GitHub Desktop.
- (UIImage *)drawImage:(UIImage *)profileImage withBadge:(UIImage *)badge withText:(NSString *)count {
UIGraphicsBeginImageContextWithOptions(profileImage.size, NO, 0.0f);
[profileImage drawInRect:CGRectMake(0, 0, profileImage.size.width, profileImage.size.height)];
[badge drawInRect:CGRectMake(profileImage.size.width - badge.size.width, 0, badge.size.width, badge.size.height)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, badge.size.width, badge.size.height)];
label.text = count;
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont systemFontOfSize:11.f];
label.textColor = [UIColor whiteColor];
[label drawTextInRect:CGRectMake(profileImage.size.width - badge.size.width, 0, badge.size.width, badge.size.height)];
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment