Question

I'm trying to make a custom activity indicator and set the size and location to: (x-coordinates 280; y-coordinates 5; height 34; width 34) I have the code:

UIImage *statusImage = [UIImage imageNamed:@"activity1.png"];
    UIImageView *activityImageView = [[UIImageView alloc]
                                      initWithImage:statusImage];

            activityImageView.animationImages = [NSArray arrayWithObjects:
                                         [UIImage imageNamed:@"activity1.png"],
                                         [UIImage imageNamed:@"activity2.png"],
                                         [UIImage imageNamed:@"activity3.png"],
                                         [UIImage imageNamed:@"activity4.png"],
                                         [UIImage imageNamed:@"activity5.png"],
                                         [UIImage imageNamed:@"activity6.png"],
                                         [UIImage imageNamed:@"activity7.png"],
                                         [UIImage imageNamed:@"activity8.png"],
                                         [UIImage imageNamed:@"activity9.png"],
                                         [UIImage imageNamed:@"activity10.png"],
                                         [UIImage imageNamed:@"activity11.png"],
                                         [UIImage imageNamed:@"activity12.png"],
                                         [UIImage imageNamed:@"activity13.png"],
                                         [UIImage imageNamed:@"activity14.png"],
                                         [UIImage imageNamed:@"activity15.png"],
                                         [UIImage imageNamed:@"activity16.png"],
                                         [UIImage imageNamed:@"activity17.png"],
                                         [UIImage imageNamed:@"activity18.png"],
                                         nil];

    activityImageView.animationDuration = 0.8;

    [activityImageView startAnimating];

    [self.view addSubview:activityImageView];

which makes the circle and understand I need the code:

activityImageView.frame = CGRectMake(
                                             self.view.frame.size.width/2
                                             -statusImage.size.width/2,
                                             self.view.frame.size.height/1.2
                                             -statusImage.size.width/1.2,
                                             statusImage.size.width,
                                             statusImage.size.height);

although my problem is I do not understand how to make the coordinates and size to what I want using this bit of code. Help much appreciated!

Was it helpful?

Solution

Looks like you just need to do:

activityImageView.frame = CGRectMake(280, 5, 34, 34);

The first 2 parameters in CGRectMake call above are the X and Y coordinates of the view's top left corner relative to its superview. The remaining parameters are the desired width and height of the view.

Also, don't forget to add your image view to a superview, e.g.

[self.view:addSubview:activityImageView];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top