swift - Positioning spinner within UIAlertController -


i have uialertcontroller title , spinner. need spinner displayed below title, i'm struggling position it. in fact, i'm setting spinner.center center of screen, it's appearing in lower right hand corner.

var alert: uialertcontroller = uialertcontroller(title: "fetching new music", message: nil, preferredstyle: uialertcontrollerstyle.alert)  var spinner: uiactivityindicatorview = uiactivityindicatorview(activityindicatorstyle: uiactivityindicatorviewstyle.whitelarge)  spinner.color = uicolor.yellowcolor()  spinner.startanimating()  alert.view.addsubview(spinner)  var height:nslayoutconstraint = nslayoutconstraint(item: alert.view, attribute: nslayoutattribute.height, relatedby: nslayoutrelation.equal, toitem: nil, attribute: nslayoutattribute.notanattribute, multiplier: 1, constant: self.view.frame.height * 0.15)  alert.view.addconstraint(height)  // here need help!           spinner.center = cgpointmake((self.view.frame.width / 2) - (spinner.frame.width / 2), (self.view.frame.height / 2) - (spinner.frame.height / 2))  self.presentviewcontroller(alert, animated: true, completion: nil) 

these 2 lines, taken together, make no sense:

alert.view.addsubview(spinner) spinner.center = cgpointmake((self.view.frame.width / 2) - (spinner.frame.width / 2), (self.view.frame.height / 2) - (spinner.frame.height / 2)) 

it appear have not grasped fundamental difference between frame , bounds. if going add spinner subview of alert view (as in first line), position of spinner's center (as in second line) defined in relation the alert view's bounds, not other object's frame.


Comments