开发者社区> 问答> 正文

为什么NSLayoutConstraint在UIView 上不起作用

NSLayoutConstraint *leftSpace =[NSLayoutConstraint
                                    constraintWithItem:_unloadBtn
                                    attribute:NSLayoutAttributeCenterY
                                    relatedBy:NSLayoutRelationEqual
                                    toItem:self
                                    attribute:NSLayoutAttributeCenterY
                                    multiplier:1
                                    constant:0];
    //    NSArray *selfConstraints=@[leftSpace];
    [self addConstraint:leftSpace];

虽然没有报错,但是不起作用。
几个问题

我想做一个 view 来嵌入到UITableViewCell中,刚开始用的viewcontroller,但是把对象数据赋给view的时候,view controller那个类总是null。(在viewcell的layoutsubview中赋值的)失败后看案例是直接用UIView.我就用UIView试试。
UIview中使用NSLayoutConstraint,不知道咋弄的,望大神指点一下。

展开
收起
a123456678 2016-07-28 11:25:09 2166 0
1 条回答
写回答
取消 提交回答
  • _unloadBtn 是否设置了
    
    _unloadBtn.translatesAutoresizingMaskIntoConstraints = NO;
    2019-07-17 20:01:14
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载