Changing the size of the UIImage

102 views Asked by At

I have the following code

    else if([annotation.title isEqualToString:NSLocalizedString(@"TITLE 1",nil)]|| [annotation.title isEqualToString:NSLocalizedString(@"TITLE 2",nil)])
    {
        static NSString *identifier = @"currentLocation";
        SVPulsingAnnotationView *pulsingView = (SVPulsingAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

        if(pulsingView == nil) {
            pulsingView = [[SVPulsingAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            pulsingView.annotationColor = [UIColor colorWithRed:0 green:0.678431 blue:0 alpha:1];
            pulsingView.image = [UIImage imageNamed:@"image.png"];
            pulsingView.frame = CGRectMake(0, 0, 15, 15);
            pulsingView.canShowCallout = YES;
        }
        return pulsingView;

Basically it's an image and besides it we have a pulsing round annotation. When the image is tapped - the annotation description with either "Title 1" or "Title 2" comes up depending on the conditions (which are not relevant here).

The issue is simple - when i apply

            pulsingView.frame = CGRectMake(0, 0, 15, 15);

The image on top of the pulsing view doesn't change size.

Need help with alternative solutions.

Thank you so much guys!

2

There are 2 answers

1
Massimo Polimeni On

1) Try this

[pulsingView setFrame: CGRectMake(0, 0, 15, 15)];

instead of

pulsingView.frame = CGRectMake(0, 0, 15, 15);

2) If the first solution doesn't work maybe you need to disable the autolayout if you are using Storyboard or...


3) if you use XIB maybe you need to add

[pulsingView setNeedsDisplay];
1
j_gonfer On

If previous answer doesn't work, a little trick that I've used sometimes is calling setTranslatesAutoresizingMaskIntoConstraints:.

Your code would look like:

[pulsingView setTranslatesAutoresizingMaskIntoConstraints:YES];