#import <UIKit/UIKit.h>
@interface UIImage (QRCode)
- (UIImage *)imageWithIcon:(UIImage *)icon;
@end
#import "UIImage+QRCode.h"
@implementation UIImage (QRCode)
- (UIImage *)imageWithIcon:(UIImage *)icon
{
UIGraphicsBeginImageContext(self.size);
// 1. 画二维码
[self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
// 2. 画头像 (头像 20% * 20%)
CGFloat wh = self.size.width * 0.2;
CGRect iconRect = CGRectMake((self.size.width - wh) * 0.5, (self.size.height - wh) * 0.5, wh, wh);
[icon drawInRect:iconRect];
// 3. 拿图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
@end
工具类:在一张图片中央添加图片
最新推荐文章于 2025-07-17 15:37:30 发布