googleads-consent-sdk-ios icon indicating copy to clipboard operation
googleads-consent-sdk-ios copied to clipboard

App icon without round corners on iOS

Open codenia opened this issue 6 years ago • 2 comments

Apple recommends to use app icon without round corners.

[UIImage imageNamed:iconName]; loads and displays the rectangular icon. That doesn't look nice.

I would use this code to make the corners round. It's not the orignal rounding of Apple, but it looks better than rectangle.

/// Returns an icon with rounded corners.
static UIImage * roundCornerIcon(UIImage * icon)
{
    CGSize size = CGSizeMake(icon.size.width*icon.scale, icon.size.height *icon.scale);
    UIGraphicsBeginImageContextWithOptions(size, NO, 1.0);
    float radius = size.width * 0.25;
    [[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, size.width, size.height)
                                cornerRadius:radius] addClip];
    [icon drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage * roundCornerIcon = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return roundCornerIcon;
}

/// Returns the application's icon as a data URI string.
static NSString *_Nonnull PACIconDataURIString(void) {
  NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  NSArray<NSString *> *iconFiles =
      infoDictionary[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];
  NSString *iconName = iconFiles.lastObject;
  if (!iconName) {
    return @"";
  }
   
  UIImage *iconImage = roundCornerIcon([UIImage imageNamed:iconName]);
   
  NSData *iconData = UIImagePNGRepresentation(iconImage);
  NSString *iconBase64String = [iconData base64EncodedStringWithOptions:0];

  return [@"data:image/png;base64," stringByAppendingString:iconBase64String];
}

codenia avatar Jun 01 '18 09:06 codenia

Here is the comparison. Rectangle vs rounded.

icon

codenia avatar Jun 01 '18 18:06 codenia

nice solution! I agree they should add this

Izzyjm avatar Mar 25 '19 19:03 Izzyjm