天天看點

iphone,ipad畫矩形、文字、線

畫矩形、文字、線

畫無框矩形

//設定矩形填充顔色:紅色
    CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
	//填充矩形
    CGContextFillRect(context, rect);
	//執行繪畫
    CGContextStrokePath(context);
           

畫有框矩形

//設定矩形填充顔色:紅色
	CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
	//填充矩形
	CGContextFillRect(context, rect);
	//設定畫筆顔色:黑色
	CGContextSetRGBStrokeColor(context, 0, 0, 0, 1);
	//設定畫筆線條粗細
    CGContextSetLineWidth(context, 1.0);
	//畫矩形邊框
	CGContextAddRect(context,rect);
	//執行繪畫
    CGContextStrokePath(context);
           

畫文字

//設定畫筆線條粗細
	CGContextSetLineWidth(context, 1.0);
	//設定矩形填充顔色:紅色
    CGContextSetRGBFillColor (context, 1.0, 0.0, 0.0, 1.0);
	//設定字型
    UIFont *font = [UIFont boldSystemFontOfSize:31.0];
	//在指定的矩形區域内畫文字
    [text drawInRect:rect withFont:font];
           

畫線

//設定畫筆線條粗細
	CGContextSetLineWidth(context, 5.0);
	//設定線條樣式
	CGContextSetLineCap(context, kCGLineCapButt);
	//設定畫筆顔色:黑色
	CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);
	//畫點連線
	CGContextAddLines(context, points, count);
	//執行繪畫
    CGContextStrokePath(context);