Search code examples
iosobjective-cmathcgrectcgfloat

How to get the mid point of origin?


How to get x1 &x2 origin?

self.spinner=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    float x1,x2,y1,y2;
    x1=self.view.frame.origin.x;
    x2=self.view.frame.origin.x;
    y1=self.view.frame.origin.y;
    y2=self.view.frame.origin.y;



    self.spinner.center=CGPointMake((x1+x2)/2,(y1+y2)/2);

     [self.spinner startAnimating];
     [self.view addSubview:self.spinner];

i have a spinner,i try to place a spinner in mid point ,i know the concept but how to get that x1&x2 origin really i have confused with this...


Solution

  • I think you are not making point by

    float x1,x2,y1,y2;
    x1=self.view.frame.origin.x;
    x2=self.view.frame.origin.x;
    y1=self.view.frame.origin.y;
    y2=self.view.frame.origin.y;
    

    If you have to put indicator in the center of view,

    self.spinner.center = self.view.center;