xcode - Swift Activity Indicator and Label -
i'm trying simple task of creating activity indicator label says, "loading" or "saving" or whatever program when running. can not seem figure out how directly under activity indicator though, right right along side of , want to centered below it.
here code:
public func show(viewcontroller : uiviewcontroller) { async.main { self.spinner = uiactivityindicatorview(frame: cgrectmake(0, 0, self.size, self.size)) self.activitylabel = uilabel(frame: cgrectmake(0,0,200,200)) if let spinner = self.spinner { spinner.activityindicatorviewstyle = self.style let screensize: cgrect = uiscreen.mainscreen().bounds spinner.center = cgpoint (x: screensize.width/2 , y: screensize.height/2) spinner.hideswhenstopped = true viewcontroller.view.addsubview(spinner) spinner.startanimating() self.activitylabel?.center = cgpoint (x: screensize.width/2 , y: screensize.height/1.9 ) self.activitylabel?.text = self.textmessage viewcontroller.view.addsubview(self.activitylabel!) } } }
thanks help!
i think problem having label being misaligned fact didn't set label's textalignment center. need add:
self.activitylabel.textalignment = .center
that should put text inside label directly under spinner.
Comments
Post a Comment