编程知识 cdmana.com

IOS nails to add watermark to interface or image

as follows

#import "UIView+WaterMark.h"

@implementation UIView (WaterMark)

-(void)addWaterMarkText:(NSString*)waterText WithTextColor:(UIColor*)color WithFont:(UIFont*)font{
    // Calculate the width and height of the watermark text
     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.5/80; // How many rows?
    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;// Distinguish the display according to the current screen , Otherwise it will blur
            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(j*(textSize.width+30),  i*60, textSize.width, textSize.height);
            // Rotating text
            textLayer.transform = CATransform3DMakeRotation(-M_PI/5, 0,0,3);
            [self.layer addSublayer:textLayer];
            
        }
    }
}



























@end
 

版权声明
本文为[osc_3361hjxk]所创,转载请带上原文链接,感谢

Scroll to Top