Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9060213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:10:07+00:00 2026-06-16T15:10:07+00:00

I’ve found some posts showing how to change the UIButton’s image or imageBackground depending

  • 0

I’ve found some posts showing how to change the UIButton’s image or imageBackground depending on its state. But none of them mentioned the case where this UIButton is inside of a MKAnnotationView’s Callout bubble. Here is what I’m trying to do:

I have a lot of MKAnnotationViews on my map and I’d like the user to be able to set some of them as Favorites. And I think it should be cool if this option was available as an UIButton set as my leftCalloutAccessoryView.

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
// Here I've created the button...
// Now I set the states:

        [self.button setImage:self.image_1 forState:UIControlStateNormal];
        [self.button setImage:self.image_2 forState:UIControlStateHighlighted];
        [self.button setImage:self.image_3 forState:UIControlStateSelected];

        annotationView.leftCalloutAccessoryView = self.button;
}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
self.button.selected = YES;
}

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
if ([self annotationIsFavorite:view.annotation])
{
    [self.button setImage:self.image_3 forState:UIControlStateNormal];
}
}

I’ve tried different approaches. Is there any limitation for setting this particular state for UIButton inside the bubble ? Because UIControlStateHighlighted is working fine. I had to put that code on didSelectAnnotationView: ’cause if the annotation is already a favorite, the UIButton should appear in its selected state. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:10:09+00:00Added an answer on June 16, 2026 at 3:10 pm

    Thanks to @Anna Karenina I discovered what I was doing wrong: using a single instance of my UIButton for all annotation views. I’ve done something a little different from her suggestion in viewForAnnotation though. Instead of storing “selected” state in my custom annotation class, I’m always checking if the annotation is currently inside my Array of Favorites and if it is, I change its button state to selected. Maybe her solution is more elegant and even faster, I’ll try it later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.