iOS Development with Swift Tutorial - 23 - Drawing with Core Graphics

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

with swift 3 you can do this

let context = UIGraphicsGetCurrentContext()
context!.setLineWidth(3.0)

//make and invisible path first then we fill it in
context!.move(to: CGPoint(x: 50, y: 60))
context!.addLine(to: CGPoint(x: 250, y:320))
context!.strokePath()

and this should draw a purple line on your simulator

teakodo
Автор

Thank you very much for your "Drawing with Core Graphics" tutorial!

oscarm.sandriareynoso
Автор

What do the dots mean? Like when will I know to use them?

justinL
Автор

To anybody using the newest version of xcode this is what I got to work:

import UIKit

class Draw: UIView{
 override func draw(_ rect: CGRect){
        let context = UIGraphicsGetCurrentContext()
        context!.setLineWidth(3.0)
       

          context!.moveTo(x: 50, y: 60)
        context!.addLineTo(x: 250, y: 320)

         context!.strokePath()
}

darthvader
Автор

Here's what I got to work in Swift 4, Xcode 9.2:

override func draw(_ rect: CGRect)
{     
        // create a line
        let myLine = UIBezierPath()
        myLine.lineWidth = 3.0
        UIColor.purple.setStroke()

        // position the line
        myLine.move(to: CGPoint(x:30, y:30))
        myLine.addLine(to: CGPoint(x: 150, y: 320))

        // draw the line
        myLine.stroke()
}

Japangamer
welcome to shbcf.ru