iphone - UIActivityIndicatorView display in the center of the screen -
is there way have uiactivityindicatorview display in center of screen mirror networkactivityindicator? want same process networkactivityindicator, larger indicator more noticeable user.
try this:
uiview *view = /* whatever main view */ uiactivityindicatorview *spinner = [[uiactivityindicatorview alloc] initwithactivityindicatorstyle:uiactivityindicatorviewstylewhitelarge]; cgrect frame = spinner.frame; frame.origin.x = view.frame.size.width / 2 - frame.size.width / 2; frame.origin.y = view.frame.size.height / 2 - frame.size.height / 2; spinner.frame = frame; [view addsubview:spinner]; [spinner startanimating]; [spinner release]; // or, keep handle later stop animating this centers spinner in enclosing view, whatever might be.
if not keep handle spinner, , if spinner subview of view (or @ least in known position), later handle dipping [view subviews] it.
edit: use cgrectgetmidx() , cgrectgetmidy() instead of more complicated equations above finding x , y... mileage may vary. :-)
edit (2/25/2016)
this answer has received up-votes recently, thought update in order. there better way now. example places uiactivityindicatorview in center of uitableview.
self.spinner = [[uiactivityindicatorview alloc] initwithactivityindicatorstyle:uiactivityindicatorviewstylegray]; _spinner.translatesautoresizingmaskintoconstraints = no; _spinner.hideswhenstopped = yes; [self.tableview addsubview:self.spinner]; [self.tableview addconstraints:@[ [nslayoutconstraint constraintwithitem:_spinner attribute:nslayoutattributecenterx relatedby:nslayoutrelationequal toitem:self.tableview attribute:nslayoutattributecenterx multiplier:1 constant:0], [nslayoutconstraint constraintwithitem:_spinner attribute:nslayoutattributecentery relatedby:nslayoutrelationequal toitem:self.tableview attribute:nslayoutattributecentery multiplier:1 constant:0] ]];
Comments
Post a Comment