iOS简单的画线(UIImageVIew方式)
#import <UIKit/UIKit.h> @interface ViewController : UIViewController { UIImageView *mImageView; } @end
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; mImageView = [[UIImageView alloc] initWithFrame:self.view.frame]; mImageView.backgroundColor = [UIColor grayColor]; [self.view addSubview:mImageView]; UIGraphicsBeginImageContext(mImageView.frame.size); [mImageView.image drawInRect:CGRectMake(0, 0, mImageView.frame.size.width, mImageView.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15); CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES); CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor blueColor] CGColor]); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 100, 100); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 200, 200); CGContextStrokePath(UIGraphicsGetCurrentContext()); mImageView.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } @end