您的位置:首页 > 产品设计 > UI/UE

iOS简单的画线(UIImageVIew方式)

2012-07-31 16:32 375 查看
#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


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: