ios - In swift, how do I make layers of a view programmatically? -
in swift, have view 3 objects. want button , label on top of image. concept maybe layers in photoshop. currently, image on top of button , label, can not see button , label. how done?
my code here:
import uikit class viewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. let myfirstlabel = uilabel() let myfirstbutton = uibutton() let myfirstimage = uiimage(named: "1792614.jpg") let myfirstimageview = uiimageview(image: myfirstimage) myfirstlabel.text = "i made label on screen #toogood4you" myfirstlabel.font = uifont(name: "markerfelt-thin", size: 45) myfirstlabel.textcolor = uicolor.redcolor() myfirstlabel.textalignment = .center myfirstlabel.numberoflines = 5 myfirstlabel.frame = cgrectmake(15, 54, 300, 500) myfirstbutton.settitle("✸", forstate: .normal) myfirstbutton.settitlecolor(uicolor.bluecolor(), forstate: .normal) myfirstbutton.frame = cgrectmake(160, 284, 50, 50) myfirstbutton.addtarget(self, action: "pressed:", forcontrolevents: .touchupinside) self.view.addsubview(myfirstlabel) self.view.addsubview(myfirstbutton) self.view.addsubview(myfirstimageview) } func pressed(sender: uibutton!) { var alertview = uialertview() alertview.addbuttonwithtitle("ok") alertview.title = "title" alertview.message = "message" alertview.show() } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } }
the answer here:
self.view.addsubview(myfirstlabel) self.view.addsubview(myfirstbutton) self.view.addsubview(myfirstimageview)
when add subview, gets put @ top, achieve want, add view want @ bottom first, , 1 want on top last:
self.view.addsubview(myfirstimageview) self.view.addsubview(myfirstbutton) self.view.addsubview(myfirstlabel)
Comments
Post a Comment