Shimmer effect of fake Facebook
Description
The main use of the cagradientlayer characteristics to achieve special effects, because time is limited, and has not been encapsulated, to be improved later.
Effect
Source code (source code is not encapsulated, details are not processed, hope forgive)
////FadeString.h//Fadewords////Created by youxianming on 15/5/7.//Copyright (c) 2015 youxianming. All rights reserved.//#import<UIKit/UIKit.h>@interfaceFadestring:uiview/** * Enter text*/@property (nonatomic, strong) NSString*text;/** * Fade to Right fades*/- (void) Faderight;@end
////FADESTRING.M//Fadewords////Created by youxianming on 15/5/7.//Copyright (c) 2015 youxianming. All rights reserved.//#import "FadeString.h"@interfacefadestring () @property (nonatomic, strong) UILabel*label; @property (Nonatomic, strong) UILabel*BackLabel, @property (nonatomic, strong) UIView*mask;//Mask as Mask@end@implementationfadestring-(Instancetype) initWithFrame: (CGRect) frame { self=[Super Initwithframe:frame]; if(self) {//Create a label[self createLabel:self.bounds]; //Create a mask[self createMask:self.bounds]; } returnSelf ;}- (void) Createlabel: (CGRect) frame {Self.label=[[UILabel alloc] initwithframe:frame]; Self.label.font= [Uifont fontwithname:@"Avenirnext-ultralight"Size $. f]; Self.label.textAlignment=Nstextalignmentcenter; Self.label.textColor= [[Uicolor Cyancolor] Colorwithalphacomponent:0.5f]; [Self AddSubview:self.label];}- (void) Createmask: (CGRect) Frame {//Create a gradient layerCagradientlayer *gradientlayer =[Cagradientlayer layer]; Gradientlayer.frame=frame; Gradientlayer.colors= @[(__bridgeID) [Uicolor Clearcolor]. Cgcolor, (__bridgeID) [Uicolor Blackcolor]. Cgcolor, (__bridgeID) [Uicolor Blackcolor]. Cgcolor, (__bridgeID) [Uicolor Clearcolor]. Cgcolor]; Gradientlayer.locations= @[@(0.01), @(0.2), @(0.4), @(0.59)]; Gradientlayer.startpoint= Cgpointmake (0,0); Gradientlayer.endpoint= Cgpointmake (1,0); //Create and take over maskSelf.mask =[[UIView alloc] initwithframe:frame]; //Mask Get gradient layer[Self.mask.layer Addsublayer:gradientlayer]; CGRect Newframe=Self.mask.frame; Newframe.origin.x-= $; Self.mask.frame=Newframe; Self.maskview=Self.mask;}- (void) faderight {[UIView animatewithduration:5. F animations:^{CGRect frame=Self.mask.frame; Frame.origin.x+ = (Frame.size.width + -); Self.mask.frame=frame; }]; }/** * Override Setter,getter Method*/@synthesizeText =_text;- (void) SetText: (NSString *) Text {_text=text; Self.label.text=text;}-(NSString *) Text {return_text;}@end
////VIEWCONTROLLER.M//Fadewords////Created by youxianming on 15/5/7.//Copyright (c) 2015 youxianming. All rights reserved.//#import "ViewController.h"#import "FadeString.h"@interfaceViewcontroller () @property (nonatomic, strong) UILabel*label; @property (Nonatomic, strong) fadestring*fadestring;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Blackcolor]; Self.label= [[UILabel alloc] Initwithframe:cgrectmake (0,0, -, -)]; Self.label.font= [Uifont fontwithname:@"Avenirnext-ultralight"Size $. f]; Self.label.center=Self.view.center; Self.label.textAlignment=Nstextalignmentcenter; Self.label.textColor=[Uicolor Graycolor]; Self.label.text=@"youxianming"; [Self.view AddSubview:self.label]; //Create fadestringself.fadestring = [[Fadestring alloc] Initwithframe:cgrectmake (0,0, -, -)]; Self.fadeString.text=@"youxianming"; Self.fadeString.center=Self.view.center; [Self.view addSubview:self.fadeString]; [Self performselector: @selector (Run) withobject:nil Afterdelay:4. f];}- (void) Run {//Performing animation effects[self.fadestring faderight];}@end
Key settings
Shimmer effect of fake Facebook