Skip to content

Instantly share code, notes, and snippets.

@adow
adow / gist:7801157
Created December 5, 2013 06:48
mask layer
_maskLayer=[[CAGradientLayer layer]retain];
_maskLayer.frame=self.bounds;
_maskLayer.colors=@[(id)[UIColor colorWithRed:255/255.0f green:255.0f/255.0f blue:255/255.0f alpha:1.0f].CGColor,
(id)[UIColor colorWithRed:255/255.0f green:255.0f/255.0f blue:255/255.0f alpha:0.0f].CGColor];
_maskLayer.startPoint=CGPointMake(0.5, 0.3f);
_maskLayer.endPoint=CGPointMake(0.5f, 1.0f);
_maskLayer.locations=@[@0.0f,@1.0f];
self.layer.mask=_maskLayer;
@adow
adow / gist:7801165
Created December 5, 2013 06:48
Make a line graident image
-(UIImage*)makeGradientImage{
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 1.0f);
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGGradientRef myGradient;
CGColorSpaceRef myColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { 0.0,0.0,0.0, 0.0, // Start color
@adow
adow / gist:7805706
Created December 5, 2013 14:10
make radial gradient image
-(UIImage*)makeGradientImage{
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 1.0f);
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGGradientRef myGradient;
CGColorSpaceRef myColorspace;
size_t num_locations = 2;
CGFloat locations[2] = { 0.2, 0.9};
CGFloat components[8] = { 0.0,0.0,0.0, 0.0, // Start color
@adow
adow / gist:7892831
Created December 10, 2013 15:49
Make an image for UIView
///为UIView创建一个截图
static inline UIImage* WKFlip_make_image_for_view(UIView* view){
double startTime=CFAbsoluteTimeGetCurrent();
if(UIGraphicsBeginImageContextWithOptions != NULL){
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0);
} else {
UIGraphicsBeginImageContext(view.frame.size);
}
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image=UIGraphicsGetImageFromCurrentImageContext();
@adow
adow / gist:7892865
Created December 10, 2013 15:51
Split an image
///分割图片
static inline NSArray* WKFlip_make_hsplit_images_for_image(UIImage* image){
CGSize halfSize=CGSizeMake(image.size.width, image.size.height/2);
UIGraphicsBeginImageContext(halfSize);
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
// Flip the coordinate system
CGContextSetTextMatrix(context, CGAffineTransformIdentity); // 2-1
CGContextTranslateCTM(context, 0, halfSize.height); // 3-1
CGContextScaleCTM(context, 1.0, -1.0); // 4-1
@adow
adow / gist:7912008
Created December 11, 2013 15:08
iOS 中的一些目录
#define PATH_HOME NSHomeDirectory() ///获取主目录
#define PATH_TEMP NSTemporaryDirectory() ///获取临时目录
#define PATH_DOCUMENT NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDirectory, YES)[0] ///获取文档目录
@adow
adow / gist:7939096
Created December 13, 2013 02:40
char* string trim
// 去掉前部的
void ltrim(char *s)
{
long l=0,p=0,k=0;
l = strlen(s);
if( l == 0 ) return;
p = 0;
while( s[p] == ' ' || s[p] == '\t' ) p++;
if( p == 0 ) return;
while( s[k] != '\0') s[k++] = s[p++];
@adow
adow / gist:8035101
Created December 19, 2013 06:12
翻转字符串
void strRev(char *s)
{
char temp, *end = s + strlen(s) - 1;
while( end > s)
{
temp = *s;
*s = *end;
*end = temp;
--end;
++s;
@adow
adow / gist:8617377
Created January 25, 2014 14:41
计算运行时间
double startTime=CFAbsoluteTimeGetCurrent();
NSLog(@"duration:%f",CFAbsoluteTimeGetCurrent()-startTime);
@adow
adow / gist:8818017
Created February 5, 2014 05:46
取消CALayer上默认的Core Animation
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
self.transform=WKFlipCATransform3DPerspectSimpleWithRotate(rotateDegree);
...
[CATransaction commit];