github地址: https://github.com/mancongiOS/UIImage.git
UIImage的Category
UIImage+ImageWaterPrint.h
#import <UIKit/UIKit.h> @interface UIImage (ImageWaterPrint) - (UIImage *)imageWater:(UIImage *)imageLogo waterString:(NSString *)waterString; @end
UIImage+ImageWaterPrint.m
#import "UIImage+ImageWaterPrint.h" @implementation UIImage (ImageWaterPrint) - (UIImage *)imageWater:(UIImage *)imageLogo waterString:(NSString *)waterString { UIGraphicsBeginImageContext(self.size); // 原始图片渲染 [self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)]; CGFloat waterX = self.size.width - 200; CGFloat waterY = self.size.height - 200; CGFloat waterW = 200; CGFloat waterH = 200; // logo 渲染 [imageLogo drawInRect:CGRectMake(waterX, waterY, waterW, waterH)]; // 渲染文字 NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]; paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping; NSDictionary * dic = @{ NSFontAttributeName : [UIFont systemFontOfSize:40], NSParagraphStyleAttributeName : paragraphStyle, NSForegroundColorAttributeName : [UIColor redColor] }; [waterString drawInRect:CGRectMake(50, 50, 200, 50) withAttributes:dic]; UIGraphicsEndPDFContext(); // UIImage UIImage * imageNew = UIGraphicsGetImageFromCurrentImageContext(); return imageNew; } @end
你的一次推荐就是对我莫大的支持。感觉不错,给个推荐或者评论吧。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步