#define CENTER_IMAGE_WIDTH 31
#define CALLOUT_HEIGHT 45
#define MIN_LEFT_IMAGE_WIDTH 16
#define MIN_RIGHT_IMAGE_WIDTH 16
#define LABEL_HEIGHT 48
#define LABEL_FONT_SIZE 15
#define ANCHOR_Y 60
-(void) addMarkerAt:(CLLocationCoordinate2D) markerPosition withTitle:
(NSString *)titulo withStyle:(NSString *)style
{
CGSize size = [titulo sizeWithFont:[UIFont
boldSystemFontOfSize:LABEL_FONT_SIZE]];
float sizes = size.width;
int left_width2 = ((int)(sizes + CENTER_IMAGE_WIDTH)/2)-5;
int right_width2 = (int)(sizes + CENTER_IMAGE_WIDTH)/2;
label=[[UIView alloc]initWithFrame:CGRectMake(((-left_width2*2+21)/
2)-18, 19 - ANCHOR_Y,0 , 0)];
label.backgroundColor = [UIColor clearColor];
label.userInteractionEnabled=YES;
CALLOUT_LEFT_IMAGE = [[[UIImage imageNamed:@"callout_left.png"]
stretchableImageWithLeftCapWidth:15 topCapHeight:0] retain];
CALLOUT_CENTER_IMAGE = [[[UIImage
imageNamed:@"callout_center.png"]stretchableImageWithLeftCapWidth:30
topCapHeight:0]retain];
CALLOUT_RIGHT_IMAGE = [[[UIImage imageNamed:@"callout_right.png"]
stretchableImageWithLeftCapWidth:1 topCapHeight:0]retain];
calloutCenter = [[UIImageView alloc]
initWithFrame:CGRectMake(left_width2-5+5,0, right_width2+5+5,
CALLOUT_HEIGHT)];
calloutCenter.image = CALLOUT_CENTER_IMAGE;
[label addSubview:calloutCenter];
[calloutCenter release];
calloutLeft = [[UIImageView alloc] initWithFrame:CGRectMake(round(0),
round(0), left_width2-5+5, round(CALLOUT_HEIGHT))];
calloutLeft.image = CALLOUT_LEFT_IMAGE;
[label addSubview:calloutLeft];
[calloutLeft release];
calloutRight = [[UIImageView alloc]
initWithFrame:CGRectMake(left_width2*2+5+10, round(0), 16,
round(CALLOUT_HEIGHT))];
calloutRight.image = CALLOUT_RIGHT_IMAGE;
[label addSubview:calloutRight];
[calloutRight release];
calloutLabel = [[UILabel alloc]
initWithFrame:CGRectMake(MIN_LEFT_IMAGE_WIDTH-3, -8.5, sizes,
LABEL_HEIGHT)];
calloutLabel.font = [UIFont boldSystemFontOfSize:LABEL_FONT_SIZE];
calloutLabel.text=titulo;
calloutLabel.textColor = [UIColor whiteColor];
calloutLabel.backgroundColor = [UIColor clearColor];
[label addSubview:calloutLabel];
[calloutLabel release];
UIButton *buttongo= [UIButton
buttonWithType:UIButtonTypeDetailDisclosure];
buttongo.frame=CGRectMake(left_width2*2-3, 4, 25, 25);
buttongo.multipleTouchEnabled=YES;
buttongo.userInteractionEnabled=YES;
buttongo.enabled=YES;
[label addSubview:buttongo];
RMMarker *newMarker = [[RMMarker alloc] initWithUIImage:[UIImage
imageNamed:style] anchorPoint:CGPointMake(0, 1)];
[newMarker setLabel:label];
[newMarker hideLabel];
[mapView.contents.markerManager addMarker:newMarker
AtLatLong:markerPosition];
if (style==@"userGoogle.png") {
userMarker=newMarker;
}
NSNumber* clickCounter = [[NSNumber numberWithInt: 0] autorelease];
newMarker.data = clickCounter;
[markersToErase addObject:newMarker];
[newMarker release];
[label release];
}
- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map
{
NSInteger clickCounter = [((NSNumber*) marker.data) intValue] + 1;
NSInteger clickCounterShowed = [((NSNumber*) markerLabelShowed.data)
intValue]+1;
if (markerLabelShowed!=NULL){
[markerLabelShowed hideLabel];
markerLabelShowed.data = [NSNumber numberWithInt:
clickCounterShowed];
}
if (clickCounter%2==1) {
[marker showLabel];
markerLabelShowed=marker;
}else {
[marker hideLabel];
markerLabelShowed=NULL;
}
marker.data = [NSNumber numberWithInt: clickCounter];
}
I am sure it can be better coded, but here is done in my way.
You need the 3 images:
http://www.megaupload.com/?d=41WAJ2UA
I hope, you can understand how i create the balloons. If you have any
problem, ask me.