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
    

      

     

  • 相关阅读:
    Windows Azure 网站开发Stacks支持
    AzureDev 社区活动获奖者公布
    Android 改变窗口标题栏的布局
    cocos2d-x游戏开发系列教程-超级玛丽01-前言
    cocos2dx进阶学习之CCObject
    基于visual Studio2013解决算法导论之055拓扑排序
    查看某文件夹内文件大小
    vmstat命令
    uname 命令
    iostat命令
  • 原文地址:https://www.cnblogs.com/greywolf/p/2617055.html
Copyright © 2011-2022 走看看