zoukankan      html  css  js  c++  java
  • 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
    

      

     

  • 相关阅读:
    DOM 与BOM
    尝试json文件导入数据
    js事件监听简介
    js事件简介
    js中的for语句简介
    作业练习正则表达式
    简单总结-BOM
    web前端第三次作业em,fr,rem,px简单解释及颜色表
    web第二次作业练习grid
    web前端课程第一次作业----注册页面代码(2018-9-14)
  • 原文地址:https://www.cnblogs.com/greywolf/p/2617055.html
Copyright © 2011-2022 走看看