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 7692533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:52:27+00:00 2026-05-31T20:52:27+00:00

I have created a custom annotation view. In the setSelected method i have implemented

  • 0

I have created a custom annotation view. In the setSelected method i have implemented a view as i need, now i want add a button to that view. But the button not detecting the click event,
it absorbed by the mapview. what should i do for adding button like rightcalloutaccessory.
Thanks in advance.

  • 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-05-31T20:52:29+00:00Added an answer on May 31, 2026 at 8:52 pm

    I solved this problem by changing control event for the UIButton as

    [button addTarget:self action:@selector(clickEvent) forControlEvents:UIControlEventTouchDown]
    

    Below is the part of my code to create custom annotations.

        - (CustomAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation
        {
            if ([annotation isKindOfClass:[CustomAnnotation class]])
            {
                 CustomAnnotationView *newAnnotationView = nil;
        // determine the type of annotation, and produce the correct type of annotation view for it.
    
                 newAnnotationView = [[[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil delegate: targetController] autorelease];
                 [newAnnotationView setEnabled:YES];
                 [newAnnotationView setCanShowCallout:NO];
                 return newAnnotationView;
           }
        }
    
    
    
    
    
        @interface CustomAnnotationView : MKAnnotationView 
        {
        }
        @end
    
    
        @implementation CustomAnnotationView
    
        - (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier delegate:(id)targetController
        {
                self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
                /* Set initial width as you want. ex: 50X50*/
                self.frame = CGRectMake(0, 0, Initial_width, Initial_height); 
                 self.backgroundColor = [UIColor redColor];
                 return self;
        }
    
        /* When you tap on an annotation this method is fired*/ 
        - (void)setSelected:(BOOL)selected animated:(BOOL)animated
        {
            if(selected){
                /* When you select annotation, instead of showing default callout you can increase the width &height of annotation and add your custom view here*/ 
                    self.frame = CGRectMake(0, 0, max_width, max_height);
                    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(6, 0, max_width-10, max_height)];
                    view.backgroundColor = [UIColor blackColor];
    
                    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];       
                        UIImage *img = [UIImage imageNamed:@"image.png"];
                    but = CGRectMake(x , y, img.size.width + 20,  img.size.height + 15);
                    [but setImage:img forState:UIControlStateNormal];
                    [but addTarget:targetController action:@selector(methodName) forControlEvents:UIControlEventTouchDown];
                    [view addSubview:but];
    
                    [self addSubview:view];
            }
            else {
                    /* When you tap outside of annotation, set the initial frame for the annotation. and remove the custom view from annotation*/
                    self.frame = CGRectMake(0, 0, Initial_width, Initial_height);
                    [view removeFromSuperview];
    
                }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created Custom Annotation with following: -(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { MKPinAnnotationView *view =
I have created a custom list as a feature in sharepoint. i need to
I have created a custom workflow activity that copies attachments from a case to
I have created a custom tag that looks like this: def textField = {
I have some map view controller and I have a custom annotation. Custom annotation
I have created custom result class to serialize json data to xml. I want
I have created a Custom View component and my layout file consists of a
I have created a custom module that creates a custom Database table. I have
I have created custom post types that also have custom meta_boxes I've created. Currently,
I have created many annotation in my life and now came to strange case

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.