MapView annotation not showing Images and Detail Disclosure Button - iOS Mapkit Xcode 6 Objective C - objective-c

I am adding 2 annotations in mapview with leftcalloutaccessoryview (with an image) and rightcalloutacessoryview (with detail disclosure button). The problem is that it is working fine but only for one annotation, not for both. It shows one annotation with image and detail disclosure button that can be tapped while second annotation shows only title, no image and no detail disclosure button and it can not be tapped. Here is my code.
-(void)viewDidLoad{
[super viewDidLoad];
myLocationManager=[[CLLocationManager alloc] init];
geocoder = [[CLGeocoder alloc] init];
myLocationManager.delegate=self;
myLocationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;
myLocationManager.distanceFilter=10.0;
[myLocationManager startUpdatingLocation];
mapView = [[MKMapView alloc]initWithFrame:
CGRectMake(10, 255, 300, 205)];
mapView.delegate = self;
mapView.centerCoordinate = CLLocationCoordinate2DMake(37.32, -122.03);
mapView.mapType = MKMapTypeStandard;
[self startAddingAnnottaions];
[self.view addSubview:mapView];
}
//startAddingAnnotations now
-(void)startAddingAnnottaions{
//first annotation
CLLocationCoordinate2D location;
location.latitude = (double) 37.331768;
location.longitude = (double) -122.020039;
MapAnnotation *newAnnotation = [[MapAnnotation alloc]
initWithTitle:#"Apple Head quaters" subtitle:#"subtitle" andCoordinate:location];
[mapView addAnnotation:newAnnotation];
//second annotation
CLLocationCoordinate2D location2;
location2.latitude = (double) 37.35239;
location2.longitude = (double) -122.025919;
MapAnnotation *newAnnotation2 = [[MapAnnotation alloc]
initWithTitle:#"Test Annotation" subtitle:#"parse" andCoordinate:location2];
[mapView addAnnotation:newAnnotation2];
}
//didAddAnnotationViews
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mapPoint = [annotationView annotation];
annotationView.canShowCallout = YES;
annotationView.calloutOffset = CGPointMake(0, 32);
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.rightCalloutAccessoryView = rightButton;
UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"orageSquare.png"]];
annotationView.leftCalloutAccessoryView = iconView;
MKCoordinateRegion region;
region.center = [mapPoint coordinate];
MKCoordinateSpan span;
span.latitudeDelta = 0.0144927536; // 0.0144927536 is equivalent to 1 mile
span.longitudeDelta = 0.0144927536;
region.span = span;
[mv setRegion:region animated:YES];
[mv selectAnnotation:mapPoint animated:YES];
}
//callout Accessory Control Tapped
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
id <MKAnnotation> annotation = [view annotation];
NSLog(#"Right Button Pressed");
[self performSegueWithIdentifier:#"mapToOtherInfo" sender:self];
}
What am I doing wrong? It should show multiple annotations with image and detail disclosure button. Why is it showing only one annotation with them? sometimes first one works fine, sometimes second one does but both don't work fine together.

You should set leftCalloutAccessoryView and rightCalloutAccessoryView property in viewForAnnotation method, not didAddAnnotationViews. Then you can show both annotation.
example:
- (MKAnnotationView *)mapView:(MKMapView*)mapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
if (annotation == mapView.userLocation) {
return nil;
}
MKPinAnnotationView *annotationView;
NSString *identifier = #"Pin";
annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (nil == annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
}
UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"frame_blue.png"]];
annotationView.leftCalloutAccessoryView = iconView;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return annotaionView;
}

Related

Map annotation not showing accessory view properly

I am adding some annotations to a MKMapView and these annotations have a UIImageView, loaded asynchronously with AFNetworking, as left callout accessory view. Here's the implementation:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *identifier = #"MapAnnotation";
if ([annotation isKindOfClass:[MapAnnotation class]]) {
MKAnnotationView *annotationView = (MKAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:#"map_pin"];
UIImageView *userAvatar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[userAvatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/picture?type=small",[[(MapAnnotation *)annotation user] facebookID]]] placeholderImage:[UIImage imageNamed:#"user_placeholder"]];
userAvatar.layer.cornerRadius = 4.0;
userAvatar.layer.masksToBounds = YES;
userAvatar.layer.borderColor = [[UIColor blackColor] CGColor];
userAvatar.layer.borderWidth = 1;
annotationView.leftCalloutAccessoryView = userAvatar;
UIButton *rightCallout = [UIButton buttonWithType:UIButtonTypeInfoLight];
annotationView.rightCalloutAccessoryView = rightCallout;
}
annotationView.annotation = annotation;
return annotationView;
}
return nil;
}
The problem here is: sometimes (not all the times) when annotations for different users are loaded into the map, they show the same image for all of them.
Let's say I have to load two annotations with this information:
Annotation 1
Name (title): Joshua
Datetime (subtitle): 19/06, 11:00
Image: www.myurl.com/joshua.jpg
Annotation 2
Name (title): Mathew
Datetime (subtitle): 10/06, 20:00
Image: www.myurl.com/mathew.jpg
Sometimes they are shown with title and subtitle correctly but the image loaded is the same for all of them (joshua's image or vice versa).
Am I missing something here is this method?
The call to dequeueReusableAnnotationViewWithIdentifier: will at the first call return nil which will satisfy annotationView == nil and set up your annotation view. So all the following calls to dequeueReusableAnnotationViewWithIdentifier: will return the first created annotation view with the assigned avatar image.
So [userAvatar setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/picture?type=small",[[(MapAnnotation *)annotation user] facebookID]]] placeholderImage:[UIImage imageNamed:#"user_placeholder"]]; is only called once.
You need to move annotation specific changes to the annotation view outside the "if nil" setup scope.
So you should instead set the userAvatar image each time the mapview ask for a annotationView.
So something like this:
MKAnnotationView *annotationView = (MKAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:#"map_pin"];
UIImageView *userAvatar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
userAvatar.layer.cornerRadius = 4.0;
userAvatar.layer.masksToBounds = YES;
userAvatar.layer.borderColor = [[UIColor blackColor] CGColor];
userAvatar.layer.borderWidth = 1;
annotationView.leftCalloutAccessoryView = userAvatar;
UIButton *rightCallout = [UIButton buttonWithType:UIButtonTypeInfoLight];
annotationView.rightCalloutAccessoryView = rightCallout;
}
[((UIImageView *)annotationView.leftCalloutAccessoryView) setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/%#/picture?type=small",[[(MapAnnotation *)annotation user] facebookID]]] placeholderImage:[UIImage imageNamed:#"user_placeholder"]];
This will assign the correct image each time the map view asks for an annotation view.
Cheers
Morten

UIImageView subclass doesn't work simultaneously gesture

I'm developing a iOs 6 app for iPad. I've developed a UIImageView subclass adding gesture recognizing (zoom, pinch and pan), but I've a problem: it doesn't admit simultaneously gestures. I first code it as a normal UIImageView, and it worked great, but now with the subclass it doesn't. My code:
image.m (UIImageView subclass)
- (id)initWithImage:(UIImage *)image {
self = [super initWithImage:image];
if (self) {
[self setMultipleTouchEnabled:YES];
[self setUserInteractionEnabled:YES];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(panDetected:)];
[super addGestureRecognizer:panRecognizer];
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(pinchDetected:)];
[super addGestureRecognizer:pinchRecognizer];
UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:#selector(rotationDetected:)];
[super addGestureRecognizer:rotationRecognizer];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapDetected:)];
tapRecognizer.numberOfTapsRequired = 2;
[super addGestureRecognizer:tapRecognizer];
NSLog(#"lkjlkj");
}
return self;}
- (void)panDetected:(UIPanGestureRecognizer *)panRecognizer {
CGPoint translation = [panRecognizer translationInView:self.superview];
CGPoint imageViewPosition = self.center;
imageViewPosition.x += translation.x;
imageViewPosition.y += translation.y;
self.center = imageViewPosition;
[panRecognizer setTranslation:CGPointZero inView: self.superview];}
- (void)pinchDetected:(UIPinchGestureRecognizer *)pinchRecognizer{
CGFloat scale = pinchRecognizer.scale;
self.transform = CGAffineTransformScale(self.transform, scale, scale);
pinchRecognizer.scale = 1.0;}
- (void)rotationDetected:(UIRotationGestureRecognizer *)rotationRecognizer{
CGFloat angle = rotationRecognizer.rotation;
self.transform = CGAffineTransformRotate(self.transform, angle);
rotationRecognizer.rotation = 0.0;}
- (void)tapDetected:(UITapGestureRecognizer *)tapRecognizer{
[UIView animateWithDuration:0.25 animations:^{
self.center = CGPointMake(CGRectGetMidX(self.superview.bounds), CGRectGetMidY(self.superview.bounds));
self.transform = CGAffineTransformIdentity;
}];}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;}
viewcontroller.m (where I create a imageview from image which doesn't respond to multiple gestures simultaneously)
image *img = [[image alloc] initWithImage:imatgetemporal];
img.center = CGPointMake(525/2, 651/2);
[[self.view viewWithTag:2] addSubview:img];
Thanks for all!!
I guess you can solve it by adding the same delegate to the UIPanGestureRecognizer, UIPinchGestureRecognizer, UIRotationGestureRecognizer and to the UITapGestureRecognizer just after declaring them. The code would be like this:
tapRecognizer.delegate = self;
pinchRecognizer.delegate = self;
rotationRecognizer.delegate = self;
tapRecognizer.delegate = self;
Hope it helps.

Cannot do MKAnnotationView animate drop with custom image

I have successfully changed MKAnnotationView to use my custom image with the following code snippet. However, my problem is that once I enable default pin animation using
annotationView.animatesDrop = YES;
The custom image is gone and default red pin is used. Is there any way to fix this?
Thanks
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(MyAnnotation *)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
static NSString* identifier = #"AnnotationIdentifier";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
//!!!!!!!annotationView.animatesDrop = YES;!!!!!!!!!!
} else {
annotationView.annotation = annotation;
}
annotationView.image = [UIImage imageNamed:#"bla.png"];
return annotationView;
}
Try smth like this:
- (void)loadView {
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view.backgroundColor = [UIColor grayColor];
[self.view setClipsToBounds:YES];
MKMapView *mapView = [[MKMapView alloc] initWithFrame:CGRectMake(10, 10, self.view.frame.size.width - 20, self.view.frame.size.height - 20)];
mapView.delegate = self;
[mapView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
mapView.mapType = MKMapTypeStandard;
[self.view addSubview:mapView];
}
#pragma mark - MKMapView Delegate Implementation
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
for (MKAnnotationView *pin in views) {
//UIButton *detailsButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
//[detailsButton addTarget:self action:#selector(detailsButtonAct:) forControlEvents:UIControlEventTouchUpInside];
pin.canShowCallout = YES;
//pin.rightCalloutAccessoryView = detailsButton;
CGRect endFrame = pin.frame;
pin.frame = CGRectOffset(pin.frame, 0, -230);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.45f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
pin.frame = endFrame;
[UIView commitAnimations];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *AnnotationViewID = #"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
annotationView.image = [UIImage imageNamed:#"map_pin.png"];
annotationView.annotation = annotation;
[annotationView addObserver:self forKeyPath:#"selected" options:NSKeyValueObservingOptionNew context:#"pinSelected"];
[annotationView setEnabled:YES];
return annotationView;
}
In case anyone wants to do this the block-based way instead of the begin/commit way (which is recommended from IOS 4 onwards):
...
[UIView animateWithDuration:0.5f
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
pin.frame = endFrame;
}
completion:^(BOOL finished){
if (finished) {
// Do some action upon completion of animation
}
}];
Thanks for the answer demon, really helpful

How to connect map annotation view buttons with database to go to another view?

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
//if it's user location, return nil
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
//try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = #"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
pinView.pinColor = MKPinAnnotationColorRed;
//button on the right for popup for pins
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:#selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
//zoom button on the left of popup for pins
UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[leftButton setTitle:annotation.title forState:UIControlStateNormal];
[leftButton addTarget:self
action:#selector(zoomToLocation:) forControlEvents:UIControlEventTouchUpInside];
pinView.leftCalloutAccessoryView = leftButton;
return pinView;
}
//for map view annotation right button
-(void)showDetails:(id)sender{
NSLog(#"Annotation Click");
//fypAppDelegate *appDelegate = (fypAppDelegate *)[[UIApplication sharedApplication] delegate];
//Attraction *attraction = (Attraction *)[appDelegate.attractions objectAtIndex:sender];
infoViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"info"];
self.infoView = viewController;
[self.navigationController pushViewController:infoView animated:true];
}
//for map view annotation left button
-(void)zoomToLocation:(id)sender{
NSLog(#"Annotation Click");
}
Above is the delegate for the map annotations. I am able to show the pins and show the map annotation view but I don't know how to link the button events to the next view (infoViewController).
So as you guys can see, the right button is the one I want to use to enable user to view more information about that place while the left button, I want to allow user to zoom in into the coordinates of that pin.
The data are from the database I've created. Below is how I did it just for reference (in case you guys might need it)
-(void)putPins
{
fypAppDelegate *appDelegate = (fypAppDelegate *)[[UIApplication sharedApplication] delegate]; //get data
[appDelegate readTopAttractions];
int i = 0;
int count = appDelegate.attractions.count;
self.mapAnnotations = [[NSMutableArray alloc] initWithCapacity:appDelegate.attractions.count];
while (i < count) {
Attraction *attraction = (Attraction *)[appDelegate.attractions objectAtIndex:i];
i++;
//Set coordinates for pin
CLLocationCoordinate2D location;
location.latitude = (double)[[attraction xCoor] doubleValue];
location.longitude = (double)[[attraction yCoor] doubleValue];
MapPin *mapPin = [[MapPin alloc] init];
[mapPin setCoordinate:location];
[mapPin setName: [attraction name]];
NSString *desc = [attraction description];
int i = 0, position;
while(i < 50){
if ([desc characterAtIndex:i] == ' '){
position = i;
i++;
}
else
i++;
}
desc = [#"" stringByAppendingFormat:#"%#%#", [desc substringToIndex:position], #"..."];
[mapPin setDescription: desc];
[self.mapAnnotations addObject:mapPin];
}
[self.mapView addAnnotations:self.mapAnnotations];
}
please do tell me if you guys need more details.
Thank you! =)
In your showDetails: and zoomToLocation: methods, you can get a reference to the annotation whose callout button was tapped by doing the following:
MapPin *ann = (MapPin *)[mapView.selectedAnnotations objectAtIndex:0];
In zoomToLocation: you can then zoom in to that annotation using:
[mapView setRegion:
MKCoordinateRegionMakeWithDistance(ann.coordinate, 500, 500)
//500 meters vertical span, 500 meters horizontal span
animated:YES];
In showDetails:, you can pass ann or its properties to the detail view.
By the way, instead of calling custom methods using addTarget in viewForAnnotation, you can use the map view's calloutAccessoryControlTapped delegate method which gives more direct access to the annotation that was tapped. For example:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
MapPin *ann = (MapPin *)view.annotation;
if (control == view.rightCalloutAccessoryView)
{
NSLog(#"calloutAccessoryControlTapped: control=RIGHT");
//show detail view (or you can call your custom method here)...
}
else
if (control == view.leftCalloutAccessoryView)
{
NSLog(#"calloutAccessoryControlTapped: control=LEFT");
//zoom in (or you can call your custom method here)...
}
else
{
NSLog(#"calloutAccessoryControlTapped: unknown control");
}
}
Make sure you remove the addTarget calls from viewForAnnotation if you decide to use the calloutAccessoryControlTapped delegate method.
You want to zoom in to the particular pin? Is that right?
Therefore you can use the setRegion:animated: - method from MKMapView.
Example:
mapView = MKMapView
location = CLLLocationCoordinate2D
METERS_PER_MILE = 1609.344 (defined as a Constant)
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:region];
[mapView setRegion:adjustedRegion animated:YES];
AppleDocs
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html
http://developer.apple.com/library/IOs/#documentation/MapKit/Reference/MapKitDataTypesReference/Reference/reference.html

objective c - hide a custom annotation view

I want to have a custom Annotation view that behaves exactly as the standard one, but mine needs to have an image inside and several texts, that's why I've implemented the tutorial on http://developer.apple.com/library/ios/#samplecode/WeatherMap/Introduction/Intro.html
But my problem is that I want the annotation view to hide and just show a pin, same thing as the default annotation view behaves but all annotations are showing and I cant figure out a way to hide them.
Any ideas?
Thanks.
[EDIT]
My current implementation of viewForAnnotation is:
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation{
NSLog(#"Item añadido");
static NSString *AnnotationViewID = #"annotationViewID";
CustomMKAnnotationView *annotationView =
(CustomMKAnnotationView *)[mapa dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[CustomMKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.annotation = annotation;
return annotationView;
}
Becuase I need the standard bubble but with an image and a couple of UILabels. But I would like to keep the standard behaviour, that is, there's a pin when the bubble is not showing, and when you tap it shows the bubble. The content of my custom bubble is implemented in "CustomMKAnnotationView".
Which is as follows:
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self != nil)
{
CGRect frame = self.frame;
frame.size = CGSizeMake(10.0, 10.0);
self.frame = frame;
// self. = [super pincolor];
self.backgroundColor = [UIColor clearColor];
self.centerOffset = CGPointMake(10.0, 10.0);
}
return self;
}
- (void)drawRect:(CGRect)rect{
CustomMKAnnotation *custom = (CustomMKAnnotation *)self.annotation;
if (custom != nil)
{
NSLog(#"El nombre es: %#", [custom nombre]);
UILabel *nombre = [[UILabel alloc]init];
UILabel *media = [[UILabel alloc]init];
PDColoredProgressView *barrita = [[PDColoredProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
[barrita setTintColor:[UIColor colorWithRed:0.6 green:0.83 blue:0.91 alpha:1.0f]];
nombre.textColor = [UIColor whiteColor];
media.textColor = [UIColor whiteColor];
nombre.font = [UIFont fontWithName:#"DIN-Bold" size:14];
media.font = [UIFont fontWithName:#"DIN-Medium" size:12];
CGSize size = [[custom nombre] sizeWithFont:nombre.font constrainedToSize:CGSizeMake(300, 20) lineBreakMode:nombre.lineBreakMode];
NSLog(#"el ancho es: %f y alto %f", size.width, size.height);
nombre.backgroundColor = [UIColor clearColor];
media.backgroundColor = [UIColor clearColor];
nombre.text = [custom nombre];
barrita.progress = [custom gente];
media.text = [NSString stringWithFormat:#"Media %# años", [custom media]];
UIImageView *fondo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"bubble_map.png"]];
nombre.frame = CGRectMake(10, 10, size.width, size.height);
media.frame = CGRectMake(10, size.height + 10, size.width, size.height);
barrita.frame = CGRectMake(10, media.frame.origin.y + 20, size.width, 10);
fondo.frame = CGRectMake(-((size.width+ 20.0f)/2), -((size.height +10)*2 + 20)-10, size.width+ 20.0f, (size.height +10)*2 + 20);
fondo.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
nombre.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[fondo addSubview:nombre];
[fondo addSubview:media];
[fondo addSubview:barrita];
[self addSubview:fondo];
[fondo release];
[nombre release];
[media release];
}
}
If you mean hiding the details of pin, have you tried creating a custom MKPinAnnotationView and set its property of canShowCallout=NO; ?
In your mapview delegate method :
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView*pinView;
if([annotation isKindOfClass:[<yourannotationclass> class]])
{
static NSString*annoIdentifier=#"AnnotationIdentifier";
pinView=(MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:annoIdentifier];
if(pinView==nil)
{
pinView=[[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annoIdentifier]autorelease ];
}
pinView.animatesDrop=NO;
pinView.canShowCallout=NO;
pinView.pinColor=MKPinAnnotationColorRed;
}
return pinView;
}