Search code examples
ioschatjsqmessagesviewcontroller

How to overrride mediaViewDisplaySize for a custom media item in JSQMessagesViewController?


I want to customize the size of a custom media item in JSQMessagesViewController. I am adding a label to a UIView and trying to set the size by setting the frame size of my container view.

UIView* containerView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 100, 100) ]
containerView.frame = CGRectMake(0.0f, 0.0f, 315.0f, 100.0f);
UILabel *label =  [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 50, 50)];
label.text = @"vendor name";
[containerView addSubview:label];

Setting frame size works for image view but now UIView. Even then, there is a white space for unfilled content in case of image view. Also, I can resize the placeholder for all the views by mediaViewDisplaySize but then I cannot customize each subclass differently.

How do I selectively set the size for placeholderview depending on the subclass?


Solution

  • In your mediaItem subclass, you'll need to override mediaViewDisplaySize. If you need different sizes for each type of mediaItem, then subclassing each will be easiest.