swift 绘图
2016-03-07 15:39
344 查看
//
// zuoView.swift
// swift 仓库
//
// Created by zuo on 16/3/7.
// Copyright © 2016年 zuo. All rights reserved.
//
import UIKit
class zuoView:
UIView {
override
func drawRect(rect: CGRect) {
super.drawRect(rect)
let context =
UIGraphicsGetCurrentContext()
CGContextSetLineWidth(context,
3)
CGContextSetStrokeColorWithColor(context,
UIColor.purpleColor().CGColor)
CGContextMoveToPoint(context,
0, 0)
CGContextAddLineToPoint(context,
150, 150)
//填充它时,消耗了路径
CGContextDrawPath(context,
CGPathDrawingMode.Stroke)
//
绘制矩形
CGContextMoveToPoint(context,50 ,
50)
//
let rect =
CGRectMake(60,
60, 100,
100)
CGContextAddRect(context, rect)
CGContextSetFillColorWithColor(context,
UIColor.purpleColor().CGColor)
CGContextDrawPath(context,
CGPathDrawingMode.Fill)
}
}
// zuoView.swift
// swift 仓库
//
// Created by zuo on 16/3/7.
// Copyright © 2016年 zuo. All rights reserved.
//
import UIKit
class zuoView:
UIView {
override
func drawRect(rect: CGRect) {
super.drawRect(rect)
let context =
UIGraphicsGetCurrentContext()
CGContextSetLineWidth(context,
3)
CGContextSetStrokeColorWithColor(context,
UIColor.purpleColor().CGColor)
CGContextMoveToPoint(context,
0, 0)
CGContextAddLineToPoint(context,
150, 150)
//填充它时,消耗了路径
CGContextDrawPath(context,
CGPathDrawingMode.Stroke)
//
绘制矩形
CGContextMoveToPoint(context,50 ,
50)
//
let rect =
CGRectMake(60,
60, 100,
100)
CGContextAddRect(context, rect)
CGContextSetFillColorWithColor(context,
UIColor.purpleColor().CGColor)
CGContextDrawPath(context,
CGPathDrawingMode.Fill)
}
}
相关文章推荐
- 奔五的人学IOS:swift练手与csdn,最近学习总结
- swift:类class是浅拷贝 结构体struct是深拷贝(代码理解)
- swift中获取数据设置时间格式
- Swift 烧脑体操(四) - map 和 flatMap
- Swift 烧脑体操(三) - 高阶函数
- swift版本拼图游戏项目源码
- swift版本拼图游戏项目源码
- Swift 烧脑体操(二) - 函数的参数
- Swift 烧脑体操(一) - Optional 的嵌套
- 《从零开始学Swift》学习笔记(Day60)——Core Foundation框架
- 《从零开始学Swift》学习笔记(Day 59)——代码排版
- 《从零开始学Swift》学习笔记(Day58)—— Swift编码规范之变量或常量声明规范
- 《从零开始学Swift》学习笔记(Day 57)——Swift编码规范之注释规范:
- swift
- 《从零开始学Swift》学习笔记(Day 56)—— Swift编码规范之命名规范
- Swift - 按钮(UIButton)的用法
- 《从零开始学Swift》学习笔记(Day 55)——使用try?和try!区别
- 《从零开始学Swift》学习笔记(Day54)——抛出错误
- 《从零开始学Swift》学习笔记(Day 53)——do-try-catch错误处理模式
- 《从零开始学Swift》学习笔记(Day 52)——Cocoa错误处理模式