Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to increase the view height and allow a multiline subtitle? #111

Open
bergstrat94 opened this issue Oct 18, 2017 · 16 comments

Comments

@bergstrat94
Copy link

Hey there,

I am wanting to increase the height of the view and display a multi line subtitle.
Is this is supported?

@namannik
Copy link
Contributor

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

@bergstrat94
Copy link
Author

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?

@namannik
Copy link
Contributor

namannik commented Oct 18, 2017

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;

@bergstrat94
Copy link
Author

Thank you.
I tried doing that and it seems to not be showing in the calloutview.

@namannik
Copy link
Contributor

Can you post the portion of code where you're creating the callout and setting the subtitle view?

@bergstrat94
Copy link
Author

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];

@namannik
Copy link
Contributor

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.)

@bergstrat94
Copy link
Author

Okay, I will try that out.
Thanks for your help :)

@bergstrat94
Copy link
Author

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

@bergstrat94
Copy link
Author

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

@namannik
Copy link
Contributor

What happens if you call sizeToFit on the subtitle?

[customSubtitleView sizeToFit];

@bergstrat94
Copy link
Author

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.

@namannik
Copy link
Contributor

namannik commented Oct 18, 2017

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;

@bergstrat94
Copy link
Author

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);

@namannik
Copy link
Contributor

namannik commented Oct 18, 2017

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.)

@bergstrat94
Copy link
Author

Good advice! I wrapped the view as you suggested but it fails to resize accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants