cdts/xdts-ios 3/TreeHole/Code/Gategory/UIView+WaterMark.m

44 lines
1.6 KiB
Mathematica
Raw Normal View History

2023-07-27 09:20:00 +08:00
//
// UIView+WaterMark.m
// Localization
//
// Created by on 2019/10/15.
// Copyright © 2019 . All rights reserved.
//
#import "UIView+WaterMark.h"
@implementation UIView (WaterMark)
-(void)addWaterMarkText:(NSString*)waterText WithTextColor:(UIColor*)color WithFont:(UIFont*)font{
//
NSString *waterMark = waterText;
CGSize textSize = [waterMark sizeWithAttributes:@{NSFontAttributeName:font}];
CGFloat height = [UIScreen mainScreen].bounds.size.height;
CGFloat width = [UIScreen mainScreen].bounds.size.width;
NSInteger line = height * 3 / FIX_SIZE(100); //
NSInteger row = 20;
for (int i = 0; i < line; i ++) {
for (int j = 0; j < row; j ++) {
CATextLayer *textLayer = [[CATextLayer alloc]init];
textLayer.contentsScale = [UIScreen mainScreen].scale;//
CFStringRef fontName = (__bridge CFStringRef)font.fontName;
CGFontRef fontRef =CGFontCreateWithFontName(fontName);
textLayer.font = fontRef;
textLayer.fontSize = font.pointSize;
textLayer.foregroundColor = color.CGColor;
textLayer.string = waterMark;
textLayer.frame = CGRectMake(-width + j*(textSize.width+30) + i * 30, i*FIX_SIZE(100), textSize.width, textSize.height);
//
textLayer.transform = CATransform3DMakeRotation(-M_PI/15, 0,0,3);
[self.layer addSublayer:textLayer];
}
}
}
@end