urrentImageContext();
// 使当前的context出堆栈
UIGraphicsEndImageContext();
// 返回新的改变大小后的图片
return scaledImage;
}
判断设备
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
NSLog(@"ipad");
}
else
{
NSLog(@"iphone or ipod");
}
判断分辨率
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIImage *logo = [UIImage imageNamed:@"3710167@qq.com"];
UIScreenMode *sm =[[UIScreen mainScreen] currentMode];
CGSize cs = sm.size;
//可以判断出屏幕分辨率
MCLog(@"%f x %f", cs.width,cs.height);
// CGRect cr = [[UIScreen mainScreen] applicationFrame];
// MCLog(@"%f x %f", cr.size.width,cr.size.height);
CGSize frame = [logo size];
CGRect viewRect = CGRectMake(10, 10, frame.width, frame.height);
//UIView* myView = [[UIView alloc] initWithFrame:viewRect];
[logoImageView setFrame:viewRect];
[logoImageView setImage:logo];
}
iphone CGContextSetLineWidth 画线的问题
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor (context, 142.0/ 255.0, 161.0/ 255.0, 189.0/ 255.0, 1.0);
CGContextSetLineWidth(context, 1.0 );//这里设置成了1但画出的线还是2px,给我们的感觉好像最小只能是2px。
CGContextMoveToPoint(context, 1.0 , 24.0 );
CGContextAddLineToPoint(context, 83.0 , 24.0 );
CGContextClosePath(context);
CGContextStrokePath(context);
原因是因为默认情况下,锯齿显示,所以它显示为宽度= 2.0,关闭消除锯齿可以解决
问题了。
CGContextSetShouldAntialias(context, NO );
获取上下文
CGContextRef context = UIGraphicsGetCurrentContext();
画一个正方形图形 没有边框
CGContextSetRGBFillColor(context, 0, 0.25, 0, 0.5);
CGContextFillRect(context, CGRectMake(2, 2, 270, 270));
CGContextStrokePath(context);
写文字
CGContextSetLineWidth(context, 1.0);
CGContextSetRGBFillColor (context, 1, 1, 1, 1.0);
UIFont *font = [UIFont boldSystemFontOfSize:11.0];
[@"fangyp" drawInRect:CGRectMake(40, 40, 80, 20) withFont:font];
画一条线
CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色
CGContextMoveToPoint(context, 20, 20);
CGContextAddLineToPoint(context, 200,20);
CGContextStroke
Path(context);
画正方形边框
CGContextSetRGBStrokeColor(context, 1, 1.0, 1.0, 1.0); <