show circle in iOS, in my old app https://itunes.apple.com/cn/app/jie-zhong-ri-ji/id513220773?mt=8
first get baby icon,and add a circle crop,after that ,Superposition it with background image
Iike this:
code
double radians (double degrees) {return degrees * M_PI/180;}-(UIImage*)createIconWithImage:(UIImage*)src{UIImage *circle=[UIImage imageNamed:@"Face@2x.png"];CGFloat width=circle.size.width;CGFloat height=circle.size.height;CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedFirst);CGContextDrawImage(context, CGRectMake(0, 0, width, height), circle.CGImage);if (src.imageOrientation == UIImageOrientationLeft) {CGContextRotateCTM (context, radians(90));CGContextTranslateCTM (context, 0, -height);} else if (src.imageOrientation == UIImageOrientationRight||src.imageOrientation == UIImageOrientationRightMirrored) {CGContextRotateCTM (context, radians(-90));CGContextTranslateCTM (context, -width, 0);} else if (src.imageOrientation == UIImageOrientationUp) {// NOTHING} else if (src.imageOrientation == UIImageOrientationDown) {CGContextTranslateCTM (context, width, height);CGContextRotateCTM (context, radians(-180.));}CGContextBeginPath(context);CGContextTranslateCTM (context, 4, 4);CGRect rect = CGRectMake(0, 0, width-12, height-12);CGContextAddEllipseInRect(context, rect);CGContextClosePath(context);CGContextClip(context);CGContextDrawImage(context, rect , src.CGImage);CGImageRef imageMasked = CGBitmapContextCreateImage(context);CGContextRelease(context);CGColorSpaceRelease(colorSpace);UIImage *image = [UIImage imageWithCGImage:imageMasked];CGImageRelease(imageMasked);return image;}
Apple CALayer Class Reference



没有评论:
发表评论