-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwatermark.m
30 lines (21 loc) · 1.16 KB
/
watermark.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
NSString *WMText = @"https://hudware-store.github.io";
UILabel *watermark;
watermark = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, window.frame.size.width / 4, 20)];
watermark.text = WMText;
watermark.adjustsFontSizeToFitWidth = YES;
watermark.center = CGPointMake(CGRectGetMinX(window.frame) + watermark.frame.size.width / 2 + 10, CGRectGetMaxY(window.frame) - watermark.frame.size.height - 5);
watermark.textAlignment = NSTextAlignmentCenter;
NSUInteger characterCount = [WMText length];
CGFloat randColor = arc4random_uniform(256) / 255.0;
int charsFinished;
CGFloat extraHue;
CGFloat smoothness = 0.02;
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString: watermark.attributedText];
for (charsFinished = 0, extraHue = 0.0; charsFinished != characterCount; charsFinished = charsFinished + 1, extraHue = extraHue + smoothness) {
[text addAttribute: NSForegroundColorAttributeName
value: [UIColor colorWithHue:randColor + extraHue saturation:1.0 brightness:1.0 alpha:1.0]
range: NSMakeRange(charsFinished, 1)];
}
[watermark setAttributedText: text];
//ADD WATERMARK TO THE VIEW YOU WANT
[window addSubview: watermark];