我一个自定义的 Cell ,布局如下:
图片设置大小、距离顶部、距离左边、距离底部
标题的左边距离图片的右边、距离顶部、距离右边
来源的左边距离图片的右边、顶部距离标题底部、距离底部、距离右边
这样设置是没问题,正常的。
但是现在我想自定义一条分隔线,草图如下:
我该如何修改?我尝试了很多次都失败了。。
Xcode 控制台狂飙 log
PS: 用了 UITableView-FDTemplateLayoutCell
来动态计算高度
问题已解决,本人对约束和 Masonry 还是不熟,还得多练练
感谢各位的耐心解答。
附上解决之后的代码:
![]() | 1 Sunnyyoung 2017-01-16 23:37:24 +08:00 via iPhone 分割线跟其他 View 没有任何约束的关联,直接固定 left right bottom 和其 height 的约束就好了阿 |
![]() | 2 Sunnyyoung 2017-01-16 23:37:56 +08:00 via iPhone 分割线用 Layer 画一个多好 |
![]() | 3 lisonfan OP |
![]() | 4 Dashit 2017-01-17 08:49:05 +08:00 make.size.height.equalTo(0.5) 应该是这样吧. |
![]() | 9 Dashit 2017-01-17 09:21:18 +08:00 newsPhoto make.size 这句去掉改成 make.width.equalTo(100). titleLabel height 的约束没有设置. classCnLabel 少了个 top. |
10 sjjvenu 2017-01-17 09:21:23 +08:00 图片控件的 top 和 bottom 都加了限制,然后又设置了 size ,应该是高度和 top,bottom 冲突了吧 |
![]() | 11 lisonfan OP @Dashit make.width.equalTo(100) 和 make.size.width.equalTo(100) 都报错报警告 Implicit conversion of 'int' to 'id' is disallowed with ARC Incompatible integer to pointer conversion passing 'int' to parameter of type '__strong id' |
![]() | 12 lisonfan OP |
14 laoyur 2017-01-17 10:09:31 +08:00 @lisonfan 回 3#,为何最后一行是 make.size.height.offset(0.5)?我对 Masonry 用得不多,都忘记了 但直觉上不应该是 make.size.height.equalTo(@1)吗? 我现在用 Cartography ,感觉用得也不是很爽,其实我更喜欢直接 storyboard ,直接拖来拖去,啪啪啪很爽快的感觉 顺便搭车问个问题, storyboard 跟 Cartography 混用约束时(比如 storyboard 排好版后,需要运行时动态加点控件之类),总是报一大堆 log ,请问有没有什么最佳实践可以遵循? |
![]() | 15 hhg200454 2017-01-17 10:31:54 +08:00 line 的约束最后一行改下: make.height.mas_equalTo(0.5); |
![]() | 17 lisonfan OP @hhg200454 是的,最开始我以为 make.size.height.offset(0.5) 仅仅设置了高度,没想到还顺带设置了宽度 现在改成 make.height.mas_offset(0.5) 就好了。 谢谢 |
![]() | 18 DingSoung 2017-01-17 10:50:11 +08:00 每次看到这样一大堆布局代码 真心觉得很傻 |
![]() | 22 2014CD2014 2017-01-17 17:49:15 +08:00 先研究透了,再深入使用 |