calloutview
calloutview copied to clipboard
Is it possible to increase the view height and allow a multiline subtitle?
Hey there,
I am wanting to increase the height of the view and display a multi line subtitle. Is this is supported?
You might try creating a custom view for your subtitle and setting this view for the callout's subtitleView
property. For example (in Swift):
let customSubtitleView = UILabel(frame: .zero)
customSubtitleView.numberOfLines = 2
customSubtitleView.text = "Line 1\nLine 2"
let myCalloutView = SMCalloutView.platform()
myCalloutView.subtitleView = customSubtitleView
Thanks for your reply.
I am pretty new to IOS dev.. Would you be able to show me how to do it in objective C?
This hasn't been tested, but here's what the equivalent in Objective-C should be:
UILabel *customSubtitleView = [[UILabel alloc] initWithFrame:CGRectZero];
customSubtitleView.numberOfLines = 2;
customSubtitleView.text = @"Line 1\nLine 2";
SMCalloutView *myCalloutView = [SMCalloutView platformCalloutView];
myCalloutView.subtitleView = customSubtitleView;
Thank you. I tried doing that and it seems to not be showing in the calloutview.
Can you post the portion of code where you're creating the callout and setting the subtitle view?
Here ya go: calloutView = [[SMCalloutView alloc] init]; calloutView.title = m.title; calloutView.hidden = NO; UILabel *customSubtitleView = [[UILabel alloc] initWithFrame:CGRectZero]; customSubtitleView.numberOfLines = 2; customSubtitleView.text = @"Line 1\nLine 2"; calloutView.subtitleView = customSubtitleView; calloutView.calloutOffset = CGPointMake(0, -CalloutYOffset); calloutView.rightAccessoryView = nil; CGRect calloutRect = CGRectZero; calloutRect.origin = point; calloutRect.size = CGSizeZero; [calloutView presentCalloutFromRect:calloutRect inView:mapView_ constrainedToView:mapView_ animated:YES];
Maybe try setting a larger size instead of CGRectZero
when creating the subtitle:
UILabel *customSubtitleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
(The sizes I used here are sort of arbitrary. I think the callout view is supposed to resize the subtitle to fit the text.)
Okay, I will try that out. Thanks for your help :)
I have yet to try the above suggestion however I was able to get behaviour similar to the desired behaviour by messing around with the subtitle and frame heights as well as specifying a number of lines for the subtitlelabel
I tried the above suggestion and It works! sort of.. It seems the calloutview is not adjusting according to the size of the subtitle view
What happens if you call sizeToFit
on the subtitle?
[customSubtitleView sizeToFit];
So, before adding that I would see "Line 1..." as the subtitle
With the above, I see "Line 1" and can see the top of the L for the second line.
The height of the calloutview itself does not change however.
Another thing you could try is wrapping your subtitle view in another view. According to the documentation in SMCalloutView.h:
wrap your view in a "generic"
UIView
if you do not want it to be auto-sized
UIView *subtitleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
[subtitleView addSubview:customSubtitleView];
myCalloutView.subtitleView = subtitleView;
I will try this. Currently I have it working by altering the following line in CalloutContainerHeight
return (CALLOUT_SUB_DEFAULT_CONTAINER_HEIGHT + self.subtitleView.frameHeight - 15);
That will work, but I've found it's usually a good idea to keep third-party libraries unmodified so that they can be easily replaced with a newer version in the future. (I've learned this lesson the hard way.)
Good advice! I wrapped the view as you suggested but it fails to resize accordingly.