Closed amcastror closed 9 years ago
I came across this issue the other day, maybe it is useful for others. You have to set the contentView.frame
to the correct size before the call out is shown on the map. Something like this:
// force layout pass on the content view
[contentView setNeedsLayout];
[contentView layoutIfNeeded];
// calculate minimum size required to display all subviews
CGSize compressedSize = [contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
CGRect frame = contentView.frame;
frame.size = compressedSize;
contentView.frame = frame;
// https://github.com/nfarina/calloutview/issues/73
UIView *container = [[UIView alloc] initWithFrame:contentView.frame];
[container addSubview:contentView];
self.calloutView.contentView = container;
I still have no idea why the last part is required but it works pretty well.
Be sure to setup all required constraints inside your custom contentView. The same rules apply as for UITableViewCellCell
s with dynamic height as described in this wonderful post on Stackoverflow.
Thanks @florianbuerger, I already finished that proyect but I'll definitely try it out next time.
Hi, has anyone tried to set auto layout constraints inside a contentView? I subclassed SMCalloutView and on init I'm adding them. For now it's a simple UIView with a UILabel inside:
But when it appears on the map it has the callout didn't take into account the view's contents. Here's a screenshot of how it looks (the conentView's background color is orange):
Any ideas?? Thanks a lot!