swift - How to act on the label control of a mouse down in OS X -


in class viewcontroller: nsviewcontroller

i have following code:

@ibaction override func mousedown(theevent: nsevent) {      self.mylabel.textcolor = nscolor.redcolor()     //either of these work set labels text value     self.mylabel.objectvalue = "hello world"     self.mylabel.stringvalue = "this test"      switch(self) {     case self.mylabel:         //change text of mylabel         break;     case self.mylabel1:         //change text of mylabel1         break;     case self.mylabel2:         //change text of mylabel2         break;     }  } 

this works change text , color of label control called mylabel, have 3 label controls on view how change color on 1 sends mouse down event? way can think switch statement in code above. think there better way how using sender of event?

i'm new os x , mac development , come .net c# world helping mac noob! using latest swift , xcode.

i did figure out how determine if 1 of nstextfield controls clicked on in mousedown event of view:

@ibaction override func mousedown(theevent: nsevent) {      var event_location: nspoint!     event_location = theevent.locationinwindow      self.mousedownevent = theevent      var cntrl_id = nstextfield()     var cntrl_frame = nsrect()     var cntrl_name = string()     var cntrl_value = string()     var hit = bool()      view in self.view.subviews [nsview] {         if let ct = view as? nstextfield {             cntrl_name = ct.identifier!             cntrl_id = ct             cntrl_frame = ct.frame             cntrl_value = ct.stringvalue             hit = cntrl_frame.contains(event_location)             if hit {                 controltomove = cntrl_id                 break             }         }     }   } 

there ways make more efficient possibly such keeping dictionary of nstextfield controls on view, , check dictionary if have "hit" on 1 of controls.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -