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
    

      

     

  • 相关阅读:
    orm操作
    模板语言
    路由
    newlib中printf库函数的实现
    调试问题记录
    GCC部分编译选项解析
    Lauterbach TRACE32使用技巧记录
    ARM32 页表映射过程
    TTBR0与TTBR1
    Camera Sensor基础知识
  • 原文地址:https://www.cnblogs.com/greywolf/p/2617055.html
Copyright © 2011-2022 走看看