ios - Draw lines in swift 3.0 -


i used following code no avail in swift 3.0 - gives me blank screen on simulator - don't know what's happening.

import uikit  class drawexample: uiview {          override func draw( _ rect: cgrect) {          let context = uigraphicsgetcurrentcontext()         context!.setlinewidth(3.0)         context!.setstrokecolor(uicolor.purple.cgcolor)          //make , invisible path first fill in         context!.move(to: cgpoint(x: 50, y: 60))         context!.addline(to: cgpoint(x: 250, y:320))         context!.strokepath()     } 

update class below:

import uikit  class drawexample: uiview {      override init(frame: cgrect) {         super.init(frame: frame)     }      required init?(coder adecoder: nscoder) {         fatalerror("init(coder:) has not been implemented")     }      override func draw( _ rect: cgrect) {         let context = uigraphicsgetcurrentcontext()         context!.setlinewidth(3.0)         context!.setstrokecolor(uicolor.purple.cgcolor)          //make , invisible path first fill in         context!.move(to: cgpoint(x: 50, y: 60))         context!.addline(to: cgpoint(x: 250, y:320))         context!.strokepath()     } } 

now make instance on view controller , add view. check below code it.

import uikit  class viewcontroller: uiviewcontroller {      override func viewdidload() {         super.viewdidload()         // additional setup after loading view, typically nib.          let draw = drawexample(frame: self.view.bounds)         view.addsubview(draw)     }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }   } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -