一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希望未来技术之巅上有你们也有我
UIImage+WaterMark(图片+水印+文字标识)下载链接
方法1:
/**
* 给图片加水印图片
*
* @param image 水印图片
* @param imgRect 水印图片所在位置,大小
* @param alpha 水印图片的透明度,0~1之间,透明度太大会完全遮盖被加水印图片的那一部分
*
* @return 加完水印的图片
*/
- (UIImage*)imageWaterMarkWithImage:(UIImage *)image imageRect:(CGRect)imgRect alpha:(CGFloat)alpha;
使用
self.icon.image = [self.icon.image imageWaterMarkWithImage:[UIImage imageNamed:@"logo1024"] imageRect:CGRectMake(150, 10, 100, 100) alpha:0.3];
效果
方法2:
/**
* 同上
*
* @param image 同上
* @param imgPoint 水印图片(0,0)所在位置
* @param alpha 同上
*
* @return 同上
*/
- (UIImage*)imageWaterMarkWithImage:(UIImage*)image imagePoint:(CGPoint)imgPoint alpha:(CGFloat)alpha;
使用
self.icon.image = [self.icon.image imageWaterMarkWithImage:[UIImage imageNamed:@"logo1024"] imagePoint:CGPointMake(100, 100) alpha:0.3];
效果
方法3:
/**
* 给图片加文字水印
*
* @param str 水印文字
* @param strRect 文字所在的位置大小
* @param attri 文字的相关属性,自行设置
*
* @return 加完水印文字的图片
*/
- (UIImage*)imageWaterMarkWithString:(nonnull NSString*)str rect:(CGRect)strRect attribute:(nullable NSDictionary *)attri;
使用
UIFont *font = [UIFont systemFontOfSize:40];
NSDictionary *attri = @{NSFontAttributeName:font,NSForegroundColorAttributeName:[UIColor systemGroupedBackgroundColor]};
self.icon_1.image = [self.icon_1.image imageWaterMarkWithString:@"文字的相关属性,自行设置" rect:CGRectMake(100, 10, 100, 200) attribute:attri];
效果
方法4:
/**
* 同上
*
* @param str 同上
* @param strPoint 文字(0,0)点所在位置
* @param attri 同上
*
* @return 同上
*/
- (UIImage*)imageWaterMarkWithString:(nullable NSString*)str point:(CGPoint)strPoint attribute:(nullable NSDictionary*)attri;
使用
UIFont *font = [UIFont systemFontOfSize:40];
NSDictionary *attri = @{NSFontAttributeName:font,NSForegroundColorAttributeName:[UIColor systemGroupedBackgroundColor]};
self.icon_1.image = [self.icon_1.image imageWaterMarkWithString:@"文字的相关属性,自行设置" point:CGPointMake(10, 10) attribute:attri];
效果
方法5:
/**
* 返回加水印文字和图片的图片
*
* @param str 水印文字
* @param strPoint 文字(0,0)点所在位置
* @param attri 文字属性
* @param image 水印图片
* @param imgPoint 图片(0,0)点所在位置
* @param alpha 透明度
*
* @return 加完水印的图片
*/
- (UIImage*)imageWaterMarkWithString:(nullable NSString*)str point:(CGPoint)strPoint attribute:(nullable NSDictionary*)attri image:(UIImage*)image imagePoint:(CGPoint)imgPoint alpha:(CGFloat)alpha;
使用
UIFont *font = [UIFont systemFontOfSize:40];
NSDictionary *attri = @{NSFontAttributeName:font,NSForegroundColorAttributeName:[UIColor systemGroupedBackgroundColor]};
self.icon_1.image = [self.icon_1.image imageWaterMarkWithString:@"文字的相关属性,自行设置" rect:CGRectMake(200, 10, 100, 200) attribute:attri image:[UIImage imageNamed:@"logo1024"] imageRect:CGRectMake(100, 20, 100, 100) alpha:0.3];
效果
方法6:
/**
* 同上
*
* @param str 同上
* @param strRect 文字的位置大小
* @param attri 同上
* @param image 同上
* @param imgRect 图片的位置大小
* @param alpha 透明度
*
* @return 同上
*/
- (UIImage*)imageWaterMarkWithString:(nullable NSString*)str rect:(CGRect)strRect attribute:(nullable NSDictionary *)attri image:(UIImage *)image imageRect:(CGRect)imgRect alpha:(CGFloat)alpha;
使用
UIFont *font = [UIFont systemFontOfSize:40];
NSDictionary *attri = @{NSFontAttributeName:font,NSForegroundColorAttributeName:[UIColor systemGroupedBackgroundColor]};
self.icon_1.image = [self.icon_1.image imageWaterMarkWithString:@"文字的相关属性,自行设置" point:CGPointMake(10, 10) attribute:attri image:[UIImage imageNamed:@"logo1024"] imagePoint:CGPointMake(10, 10) alpha:0.3];
效果