• swift下的简单的绘图实现


    import UIKit
    
    class MyView: UIView {
    
        /*
        // Only override drawRect: if you perform custom drawing.
        // An empty implementation adversely affects performance during animation.
        override func drawRect(rect: CGRect) {
            // Drawing code
        }
        */
        
        var uiImage:CGImageRef? = UIImage(named: "004.jpg")?.CGImage
    
        //----简易画板-----
        var path = CGPathCreateMutable()
        
        override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
            var p = touches.anyObject()?.locationInView(self)
            CGPathMoveToPoint(path, nil, p!.x, p!.y)
            
        }
        
        override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
            var p = touches.anyObject()?.locationInView(self)
            CGPathAddLineToPoint(path, nil, p!.x, p!.y)
            
            //执行重绘的操作
            setNeedsDisplay()
        }
        
    
        override func drawRect(rect: CGRect) {
            var context = UIGraphicsGetCurrentContext()
            
    //        CGContextSetRGBStrokeColor(context, 1, 0, 1, 1)//设置线的颜色
    //        CGContextSetLineWidth(context, 5)//设置线的宽度
    //        CGContextStrokePath(context)
    //        
    //        /*----fillpath为填充StrokePath为画线----*/
    //        
    //        //画线
    //        CGContextMoveToPoint(context, 100, 100)
    //        CGContextAddLineToPoint(context, 100, 200)
    //        CGContextAddLineToPoint(context, 200, 200)
    //        CGContextStrokePath(context)
    //        
    //        CGContextMoveToPoint(context, 100, 300)
    //        CGContextAddLineToPoint(context, 100, 400)
    //        CGContextAddLineToPoint(context, 200, 500)
    //        CGContextStrokePath(context)
    //        
    //        //画方块
    //        CGContextAddRect(context, CGRect(x: 200, y: 100,  100, height: 100))
    //        CGContextSetRGBFillColor(context, 1, 0, 0, 1)//改变方块的颜色
    //        /*--先把方块添加进去然后加边框,否则只显示边框--*/
    //        CGContextFillPath(context)
    //        CGContextStrokeRect(context, CGRect(x: 200, y: 100,  100, height:100))
    //        
    //        //画圆---弧线
    //        CGContextAddArc(context, 220, 350, 100, 0, 3.14*2, 0)
    //        CGContextSetRGBFillColor(context, 1, 0, 0, 1)
    //        CGContextFillPath(context)
    //        
    //        CGContextAddArc(context, 220, 350, 100, 0, 3.14*2, 0)//最后的0为顺时针,1为逆时针
    //        CGContextStrokePath(context)
    //        //---椭圆---宽高相等为圆形,宽高不等为椭圆
    //        CGContextAddEllipseInRect(context, CGRect(x: 50, y: 450,  200, height: 200))
    //        CGContextStrokePath(context)
    //        
    //        //------画图片
    //        //保存context------如果不保存与恢复图形会影响到后续的画图
    //        CGContextSaveGState(context)
    //        //画布的调整
    //        CGContextTranslateCTM(context, 10, 400)
    //        CGContextScaleCTM(context, 1, -1)
    //        CGContextDrawImage(context, CGRect(x: 100, y: 100,  200, height: 200), uiImage)
    //        //恢复context
    //        CGContextRestoreGState(context)
            
            
            //------简易画板
            //画板上的简单画线
    //        var path = CGPathCreateMutable()
    //        CGPathMoveToPoint(path, nil, 100, 100)
    //        CGPathAddLineToPoint(path, nil, 200, 200)
            CGContextAddPath(context, path)
            CGContextStrokePath(context)
        }
    
    }
    
  • 相关阅读:
    PHP比较操作符
    一个给图片加水印的程序
    PHP开发人员:充实您的XML工具箱
    PHP时间函数
    (Oralce)Web翻页优化实例
    PHP文件操作函数
    PHP图象函数
    PHP逻辑操作符
    PHP位操作符
    PHP目录遍历函数
  • 原文地址:https://www.cnblogs.com/anyezhuixing/p/4369636.html
Copyright © 2020-2023  润新知