Reputation: 687
I have custom MKAnnotation
where i'm implementing title()
method of MKAnnotation
protocol. My requirement is to have callout only with button and no title. But the problem is I get callout with title and button only if I implement title() method. If string returned is nil i don't see callout bubble. Please provide me a solution.
Upvotes: 1
Views: 579
Reputation: 143
Well, its a little hackish but it works. set the title to be @" " (empty space) just to make the callout pop and then you can wrap your button with a view, and add the button as a subview with origin.x of whatever center is...
MKPinAnnotationView* view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Null"];
view.canShowCallout = YES;
view.clipsToBounds = NO;
UIView * v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
v.clipsToBounds = NO;
v.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UITextField* field = [[UITextField alloc] initWithFrame:CGRectMake(-42, 0, 100, 30)];
field.textAlignment = NSTextAlignmentCenter;
field.clipsToBounds = NO;
field.autoresizingMask = UIViewAutoresizingFlexibleWidth;
field.delegate = self;
[v addSubview:field];
view.rightCalloutAccessoryView = v;
this example is with a UITextField but it will also work with your button.
Upvotes: 1