ios - How to make UI elements in class out of View Controller -


i'm making app , i'm trying make view contains label question. want view in app , because use repeatedly, made class (if want make change, can 1 place). uiview called questionview (var questionview = uiview()). problem when want make questionview subview of view. error says don't have have "view" understand. don't have view how can it? thank you

this inside question class:

import foundation import uikit  class question {      // properties:      var questionlabel = uilabel()     var questionview = uiview()      // methods:      func createquestion (input:string) {          // code .... not important          // this:         self.view.addsubview(questionview)      }      // ... next code, not important } 

update:

there solution. works think it's not correct programming standpoint. can tell me it? thank you

my class in separate swift file:

my class in separate swift file:

class labelclass {      var view = uiview()      init (view: uiview) {         self.view = view     }      var lbl = uilabel()     var lblview = uiview()      func makelabel () {          self.lbl.frame = cgrectmake(0, 0, 150, 50)         self.lbl.text = "text text text"         self.lbl.numberoflines = 0          self.lblview.frame = cgrectmake(20, 20, 150, 50)          self.lblview.addsubview(self.lbl)         self.view.addsubview(lblview)      }  } 

piece of code viewcontroller.swift:

override func viewdidload() {     super.viewdidload()      // added code:     var object = labelclass(view: self.view)     object.makelabel()  } 

i don't know swift, far know, instances of uiviewcontroller have view property, class question not, cannot add subviews it. want making subclass of uiview contains question label, or add questionlabel subview of questionview.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -