美文网首页
8.21 Draw绘图

8.21 Draw绘图

作者: jayck | 来源:发表于2016-09-05 20:45 被阅读8次

    系统提供的方法有,line线/rectangle矩形/arc弧线/ellipse椭圆/text/image

    如果希望绘制在屏幕上,应该从drawRect出发

    获取当前绘图环境(绘制到屏幕)这个是最核心的

    首在ViewController绘制一个灰色矩形
    新建一个类CustomerView,开始绘图

     let str: NSString = "这是一段需要显示的文字"
    
            str.drawAtPoint(CGPoint(x: 0, y: 0), withAttributes: [
    
                NSForegroundColorAttributeName:UIColor.yellowColor(), //前面字的颜色
    
                NSBackgroundColorAttributeName:UIColor.blueColor()    //背景颜色
    
                ])
    
            
    
            let image = UIImage(named: "btf.jpg")
    
    //        iamge?.drawatPoint(CGPoint(x: 50, y: 25))
    
    //        .drawatPoint是原图大小, .drawInRect可以缩放
    
            image?.drawInRect(CGRect(x: 20, y: 20, width: 150, height: 150))
    

    编译运行结果如下图:

    Paste_Image.png

    相关文章

      网友评论

          本文标题:8.21 Draw绘图

          本文链接:https://www.haomeiwen.com/subject/rworettx.html