Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

App icon without round corners on iOS #20

Open
codenia opened this issue Jun 1, 2018 · 2 comments
Open

App icon without round corners on iOS #20

codenia opened this issue Jun 1, 2018 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@codenia
Copy link

codenia commented Jun 1, 2018

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
Copy link
Author

codenia commented Jun 1, 2018

Here is the comparison. Rectangle vs rounded.

icon

@rampara rampara self-assigned this Jun 25, 2018
@rampara rampara added the enhancement New feature or request label Jun 25, 2018
@Izzyjm
Copy link

Izzyjm commented Mar 25, 2019

nice solution! I agree they should add this

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants