自动布局警告表视图单元格

时间:2019-07-28 13:49:44

标签: ios swift autolayout

我正在构建一个聊天布局,并且通过以编程方式添加约束来获得表格视图和自定义聊天单元,但是我收到了自动布局警告

在我的ChatMessageCell中,我有一个枚举Style用于确定聊天布局方向的前向或后向

我有messageLabel,它的{,{1}}和UITableViewCell的顶部,底部,前导或尾随锚都小于等于250

我有width,它在view视图中具有前导,尾随,底部和顶部锚点,messageLabel方法激活或停用setMessageLayout的前导或尾随锚点

  

自动布局警告

view
  

ChatMessageCell

(
    "<NSLayoutConstraint:0x6000039a3c00 UILabel:0x7ff54cc34b20'Hello how are you'.width <= 250   (active)>",
    "<NSLayoutConstraint:0x6000039a3e80 H:[UILabel:0x7ff54cc34b20'Hello how are you']-(16)-|   (active, names: '|':iOSChatApp.ChatMessageCell:0x7ff54d087600'cell_leading' )>",
    "<NSLayoutConstraint:0x6000039a3e30 iOSChatApp.ChatMessageCell:0x7ff54d087600'cell_leading'.leading == UILabel:0x7ff54cc34b20'Hello how are you'.leading - 16   (active)>",
    "<NSLayoutConstraint:0x6000039afca0 'UIView-Encapsulated-Layout-Width' iOSChatApp.ChatMessageCell:0x7ff54d087600'cell_leading'.width == 375   (active)>"
)
  

我的布局

ChatLayout1 ChatLayout2

1 个答案:

答案 0 :(得分:0)

根据您的“自动布局”警告,messageLabel的宽度和前导冲突。

警告表明这两个状态均处于活动状态

 (
"<NSLayoutConstraint:0x6000039a3c00 UILabel:0x7ff54cc34b20'Hello how are you'.width <= 250   (active)>",
"<NSLayoutConstraint:0x6000039a3e80 H:[UILabel:0x7ff54cc34b20'Hello how are you']-(16)-|   (active, names: '|':iOSChatApp.ChatMessageCell:0x7ff54d087600'cell_leading' )>",
"<NSLayoutConstraint:0x6000039a3e30 iOSChatApp.ChatMessageCell:0x7ff54d087600'cell_leading'.leading == UILabel:0x7ff54cc34b20'Hello how are you'.leading - 16   (active)>",
"<NSLayoutConstraint:0x6000039afca0 'UIView-Encapsulated-Layout-Width' iOSChatApp.ChatMessageCell:0x7ff54d087600'cell_leading'.width == 375   (active)>"
) 

如果您仔细阅读警告,控制台可能会建议您删除什么。