Skip to content

Instantly share code, notes, and snippets.

################################################################################
# .gitattributes
#
# Version 1.1
################################################################################
###
### Documents Files
###
*.pdf binary
@cook
cook / .gitignore
Last active December 14, 2015 10:59 — forked from adamgit/.gitignore
################################################################################
# .gitignore file for my projects
#
# Version 1.3.4
# 1. Add TeX ignore list.
################################################################################
###
### Special Files Should be Ignored for this Probject
###
@cook
cook / contentMode.mm
Created February 17, 2013 14:04
这段代码会令视图的内容被拉伸,但是如果drawRect:被再次调用,比如通过setNeedsDisplay,内容又会恢复原状。避免这类问题是因为绘制系统并不会因为bounds的改变而从头绘制,这个机制的行为是通过contentMode来配置的。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
MyView* mv = [[MyView alloc] initWithFrame:CGRectMake(0, 0, self.window.bounds.size.width - 50, 150)];
mv.center = self.window.center;
[self.window addSubview:mv];
mv.opaque = NO;
mv.tag = 111;
mv.backgroundColor = [UIColor whiteColor];
@cook
cook / draw-with-transform.mm
Last active December 13, 2015 20:29
利用transform的帮助,使绘制过程和坐标相互独立。
void drawStripes(void *info, CGContextRef con)
{
// assume 4x4 cell
CGContextSetFillColorWithColor(con, [[UIColor redColor] CGColor]);
CGContextFillRect(con, CGRectMake(0, 2, 4, 2));
CGContextSetFillColorWithColor(con, [[UIColor blueColor] CGColor]);
CGContextFillRect(con, CGRectMake(0, 0, 4, 2));
}
void drawArrow(CGContextRef con)
@cook
cook / draw-arrow-with-pattern.mm
Last active December 13, 2015 19:59
在Quartz 2D中使用pattern。
void drawStripes(void *info, CGContextRef con)
{
// assume 4x4 cell
CGContextSetFillColorWithColor(con, [[UIColor redColor] CGColor]);
CGContextFillRect(con, CGRectMake(0, 2, 4, 2));
CGContextSetFillColorWithColor(con, [[UIColor blueColor] CGColor]);
CGContextFillRect(con, CGRectMake(0, 0, 4, 2));
}
@cook
cook / draw-arrow-with-clipping.mm
Created February 16, 2013 11:06
如何在Quard 2D使用clipping的办法绘制。
- (void)drawRect:(CGRect)rect
{
// assume the background color is white
CGContextRef con = UIGraphicsGetCurrentContext();
// punch triangle hole in context clipping region
CGContextMoveToPoint(con, 90, 100);
CGContextAddLineToPoint(con, 100, 90);
CGContextAddLineToPoint(con, 110, 100);
@cook
cook / draw-arrow-with-gradient.mm
Last active December 13, 2015 19:58
在Quard 2D中使用gradient绘制arrow。
- (void)drawRect:(CGRect)rect
{
// assume the background color is white
CGContextRef con = UIGraphicsGetCurrentContext();
CGContextSaveGState(con);
// punch triangle hole in context clipping region
CGContextMoveToPoint(con, 90, 100);
CGContextAddLineToPoint(con, 100, 90);