@@ -372,7 +372,50 @@ -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker*)marker
372372 rightImg = [self loadImageFromGoogleMap: @" bubble_right@2x" ];
373373 float scale = leftImg.scale ;
374374 int sizeEdgeWidth = 10 ;
375-
375+
376+ int width = 0 ;
377+
378+ if (styles && [styles objectForKey: @" width" ]) {
379+ NSString *widthString = [styles valueForKey: @" width" ];
380+
381+ if ([widthString hasSuffix: @" %" ]) {
382+ double widthDouble = [[widthString stringByReplacingOccurrencesOfString: @" %" withString: @" " ] doubleValue ];
383+
384+ width = (int )((double )mapView.frame .size .width * (widthDouble / 100 ));
385+ } else if ([widthString isNumeric: widthString]) {
386+ double widthDouble = [widthString doubleValue ];
387+
388+ if (widthDouble <= 1.0 ) {
389+ width = (int )((double )mapView.frame .size .width * (widthDouble));
390+ } else {
391+ width = (int )widthDouble;
392+ }
393+ }
394+ }
395+
396+ int maxWidth = 0 ;
397+
398+ if (styles && [styles objectForKey: @" maxWidth" ]) {
399+ NSString *widthString = [styles valueForKey: @" maxWidth" ];
400+
401+ if ([widthString hasSuffix: @" %" ]) {
402+ double widthDouble = [[widthString stringByReplacingOccurrencesOfString: @" %" withString: @" " ] doubleValue ];
403+
404+ maxWidth = (int )((double )mapView.frame .size .width * (widthDouble / 100 ));
405+
406+ // make sure to take padding into account.
407+ maxWidth -= sizeEdgeWidth;
408+ } else if ([widthString isNumeric: widthString]) {
409+ double widthDouble = [widthString doubleValue ];
410+
411+ if (widthDouble <= 1.0 ) {
412+ maxWidth = (int )((double )mapView.frame .size .width * (widthDouble));
413+ } else {
414+ maxWidth = (int )widthDouble;
415+ }
416+ }
417+ }
418+
376419 // -------------------------------------
377420 // Calculate the size for the contents
378421 // -------------------------------------
@@ -382,16 +425,14 @@ -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker*)marker
382425 isTextMode = false ;
383426 NSArray *tmp = [title componentsSeparatedByString: @" ," ];
384427 NSData *decodedData;
385- #if !defined(__IPHONE_8_0)
386- decodedData = [[NSData alloc ] initWithBase64Encoding: (NSString *)tmp[1 ]];
387- #else
428+ #ifdef __IPHONE_7_0
388429 if ([PluginUtil isIOS7_OR_OVER ]) {
389- decodedData = [NSData dataFromBase64String: tmp[1 ]];
430+ decodedData = [[ NSData alloc ] initWithBase64Encoding: ( NSString *) tmp[1 ]];
390431 } else {
391- #if !defined(__IPHONE_7_0)
392- decodedData = [[NSData alloc ] initWithBase64Encoding: (NSString *)tmp[1 ]];
393- #endif
432+ decodedData = [NSData dataFromBase64String: tmp[1 ]];
394433 }
434+ #else
435+ decodedData = [NSData dataFromBase64String: tmp[1 ]];
395436 #endif
396437
397438 base64Image = [[UIImage alloc ] initWithData: decodedData];
@@ -412,15 +453,15 @@ -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker*)marker
412453 }
413454 }
414455 if (isBold == TRUE && isItalic == TRUE ) {
415- # ifdef __IPHONE_7_0
456+ if ([PluginUtil isIOS7_OR_OVER ] == true ) {
416457 // ref: http://stackoverflow.com/questions/4713236/how-do-i-set-bold-and-italic-on-uilabel-of-iphone-ipad#21777132
417458 titleFont = [UIFont systemFontOfSize: 17 .0f ];
418459 UIFontDescriptor *fontDescriptor = [titleFont.fontDescriptor
419460 fontDescriptorWithSymbolicTraits: UIFontDescriptorTraitBold | UIFontDescriptorTraitItalic];
420461 titleFont = [UIFont fontWithDescriptor: fontDescriptor size: 0 ];
421- # else
462+ } else {
422463 titleFont = [UIFont fontWithName: @" Helvetica-BoldOblique" size: 17.0 ];
423- # endif
464+ }
424465 } else if (isBold == TRUE && isItalic == FALSE ) {
425466 titleFont = [UIFont boldSystemFontOfSize: 17 .0f ];
426467 } else if (isBold == TRUE && isItalic == FALSE ) {
@@ -430,33 +471,14 @@ -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker*)marker
430471 }
431472
432473 // Calculate the size for the title strings
433- CGSize tmpSize = CGSizeMake (mapView.frame .size .width - 13 , mapView.frame .size .height - 13 );
434- #if !defined(__IPHONE_8_0)
435- textSize = [title sizeWithFont: titleFont constrainedToSize: tmpSize];
436- #else
437- NSDictionary *attr = @{ NSFontAttributeName : titleFont};
438- textSize = [title boundingRectWithSize: tmpSize
439- options: NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine
440- attributes: attr
441- context: nil ].size ;
442- #endif
474+ textSize = [title sizeWithFont: titleFont constrainedToSize: CGSizeMake (mapView.frame.size.width - 13 , mapView.frame.size.height - 13 )];
443475 rectSize = CGSizeMake (textSize.width + 10 , textSize.height + 22 );
444476
445477 // Calculate the size for the snippet strings
446478 if (snippet) {
447479 snippetFont = [UIFont systemFontOfSize: 12 .0f ];
448480 snippet = [snippet stringByReplacingOccurrencesOfString: @" \n " withString: @" " ];
449-
450-
451- #if !defined(__IPHONE_8_0)
452- snippetSize = [snippet sizeWithFont: snippetFont constrainedToSize: tmpSize];
453- #else
454- NSDictionary *attr = @{ NSFontAttributeName : snippetFont};
455- snippetSize = [snippet boundingRectWithSize: tmpSize
456- options: NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine
457- attributes: attr
458- context: nil ].size ;
459- #endif
481+ snippetSize = [snippet sizeWithFont: snippetFont constrainedToSize: CGSizeMake (mapView.frame.size.width - 13 , mapView.frame.size.height - 13 )];
460482 rectSize.height += snippetSize.height + 4 ;
461483 if (rectSize.width < snippetSize.width + leftImg.size .width ) {
462484 rectSize.width = snippetSize.width + leftImg.size .width ;
@@ -468,6 +490,14 @@ -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker*)marker
468490 } else {
469491 rectSize.width += sizeEdgeWidth;
470492 }
493+
494+ if (width > 0 ) {
495+ rectSize.width = width;
496+ }
497+ if (maxWidth > 0 &&
498+ maxWidth < rectSize.width ) {
499+ rectSize.width = maxWidth;
500+ }
471501
472502 // -------------------------------------
473503 // Draw the the info window
@@ -594,7 +624,7 @@ -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker*)marker
594624 }
595625
596626 CGRect textRect = CGRectMake (5 , 5 , rectSize.width - 10 , textSize.height );
597- # if defined(__IPHONE_7_0)
627+ if ([PluginUtil isIOS7_OR_OVER ] == true ) {
598628 // iOS7 and above
599629 NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc ] init ];
600630 style.lineBreakMode = NSLineBreakByWordWrapping;
@@ -607,41 +637,43 @@ -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker*)marker
607637 };
608638 [title drawInRect: textRect
609639 withAttributes: attributes];
610- #else
640+
641+
642+ } else {
611643 // iOS6
612644 [titleColor set ];
613645 [title drawInRect: textRect
614646 withFont: titleFont
615647 lineBreakMode: NSLineBreakByWordWrapping
616648 alignment: textAlignment];
617- # endif
649+ }
618650 // CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 0.5);
619651 // CGContextStrokeRect(context, textRect);
620652 }
621653
622654 // Draw the snippet
623655 if (snippet) {
624656 CGRect textRect = CGRectMake (5 , textSize.height + 10 , rectSize.width - 10 , snippetSize.height );
625- # if defined(__IPHONE_7_0)
626- // iOS7 and above
627- NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc ] init ];
628- style.lineBreakMode = NSLineBreakByWordWrapping;
629- style.alignment = textAlignment;
630-
631- NSDictionary *attributes = @{
632- NSForegroundColorAttributeName : [UIColor grayColor ],
633- NSFontAttributeName : snippetFont,
634- NSParagraphStyleAttributeName : style
635- };
636- [snippet drawInRect: textRect withAttributes: attributes];
637- # else
638- // iOS6
639- [[UIColor grayColor ] set ];
640- [snippet drawInRect: textRect
641- withFont: snippetFont
642- lineBreakMode: NSLineBreakByWordWrapping
643- alignment: textAlignment];
644- # endif
657+ if ([PluginUtil isIOS7_OR_OVER ] == true ) {
658+ // iOS7 and above
659+ NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc ] init ];
660+ style.lineBreakMode = NSLineBreakByWordWrapping;
661+ style.alignment = textAlignment;
662+
663+ NSDictionary *attributes = @{
664+ NSForegroundColorAttributeName : [UIColor grayColor ],
665+ NSFontAttributeName : snippetFont,
666+ NSParagraphStyleAttributeName : style
667+ };
668+ [snippet drawInRect: textRect withAttributes: attributes];
669+ } else {
670+ // iOS6
671+ [[UIColor grayColor ] set ];
672+ [snippet drawInRect: textRect
673+ withFont: snippetFont
674+ lineBreakMode: NSLineBreakByWordWrapping
675+ alignment: textAlignment];
676+ }
645677 }
646678 } else {
647679 // Draw the content image
0 commit comments