Search code examples
iosuibuttonios7uiimagemkannotationview

UIButtonTypeDetailDisclosure Color Change


I have changed the image of UIButtonTypeDetailDisclosure to the image below but the problem is that the image becomes in blue color. Where would be my issue?

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
*infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

[infoButton setImage:[UIImage imageNamed:@"carcar.png"] forState: UIControlStateNormal];

pinView.rightCalloutAccessoryView = infoButton;
} 

enter image description here

enter image description here

Last update: Solved with last infoButton.frame.

    UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeCustom];

    UIImage *carImage = [UIImage imageNamed:@"carcar.png"];

    if ([carImage respondsToSelector:@selector(imageWithRenderingMode:)])
    {
        carImage = [carImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }

    [infoButton setImage:carImage forState: UIControlStateNormal];

    infoButton.frame = CGRectMake(0, 0, 32, 32);

    pinView.rightCalloutAccessoryView = infoButton;

Solution

  • Use a custom button type:

    infoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    

    If you want to add your own image, you should always use this method. The other types are for pre-defined buttons (like info, add contact, etc.)