简体   繁体   English

JSQMessagesViewController自定义单元格自动布局问题-IOS

[英]JSQMessagesViewController Custom Cell Auto layout Issue - IOS

I am using JSQMessagesViewController and I created a custom cell according to this answer. 我正在使用JSQMessagesViewController,并且根据此答案创建了一个自定义单元格。 How to add custom view to JSQMessagesViewController cell so that it includes one view with some buttons and text view? 如何将自定义视图添加到JSQMessagesViewController单元,以使其包括一个带有一些按钮的视图和文本视图?

Now I am struggling to set auto layout constrains correctly. 现在,我正在努力正确设置自动布局约束。 So, the message bubble not display correctly. 因此,消息气泡无法正确显示。 Please help me set the constraints correctly 请帮助我正确设置约束

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

So lets take a stab at this. 因此,让我们对此采取行动。 So first things that I would do it set a constraint for the first button to be equal hight of the other. 因此,我要做的第一件事就是将第一个按钮设置为与另一个按钮相等的约束。 You can accomplish a couple of ways but I will only describe one here for brevity. 您可以通过几种方法来完成,但是为了简洁起见,在这里我只描述其中一种。 You can do hold the control button on your computer and select button1 and drag to button2 . 您可以按住计算机上的control按钮,然后选择button1并拖动到button2 This will present you with a couple of options that look like this. 这将为您提供几个看起来像这样的选项。 约束选项

You want to select Equal Heights this will make it so both your buttons have the same hight. 您要选择“ Equal Heights ,以使两个按钮都具有相同的高度。 Then you will want to give it a hight. 然后,您将需要给予很高的评价。 Once again hold down the control button on your keyboard but this time click button1 drag and release within button1 . 再次按住键盘上的control按钮,但是这次单击button1并在button1拖动并释放。 you should get something along the lines of this. 您应该对此有所了解。

单个项目的约束

If you do not get the desired options try dragging in a diagonal direction. 如果没有获得所需的选项,请尝试沿对角线方向拖动。 Xcode is tying to guess what constraints you want based on the direction of your drag. Xcode试图根据拖动的方向来猜测您想要什么约束。 IE If you drag vertically you should get the Height option. IE浏览器如果垂直拖动,则应获得“ Height选项。

Then you can go to the properties inspector on the right and set a number for how high you would like. 然后,您可以转到右侧的属性检查器并设置一个您想要的高度的数字。 Text is normally around 12pt so I would go with about 30pt or more for the hight of a button. 文字通常在12pt左右,因此我希望按钮的高度在30pt或以上。 Then add a constraint for spacing between them and leading and trailing to the containing view or you could give them a standard width and center them in the view. 然后添加一个约束,以限制它们之间以及到包含视图的前后之间的间距,或者可以给它们提供标准宽度并将其在视图中居中。 Which ever fits best for you. 哪个最适合您。

Edit: 编辑:

You should also adjust the bubble size calculation. 您还应该调整气泡大小的计算。 It can be found in the JSQMessagesBubblesSizeCalculator class. 可以在JSQMessagesBubblesSizeCalculator类中找到它。 Eg: In the 例如:在

 - (CGSize)messageBubbleSizeForMessageData {
 if([messageData isOptionMessage]){ 
  // add button height also (In this case i have set constant 200. But we have to calculate the actual button heights instead) 
     finalSize = CGSizeMake(finalWidth, stringSize.height + verticalInsets + 200)
  } else { 
       finalSize = CGSizeMake(finalWidth, stringSize.height + verticalInsets)
  }
}

Let me know if you need any more help and keep up the good work. 让我知道您是否需要更多帮助并保持良好的工作状态。 👍🏼 🚜 🚜

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM