zoukankan      html  css  js  c++  java
  • iOS autolayout 代码,自定义间距

    最近换了新的项目组,然后这个项目组是纯代码,然后我就开始试着用代码去写适配,结果学艺不精,遇到个闪退,搜了一下发现几乎没有人遇到这个问题,后来发现其实就是我自己太粗心了。

    我是这样写的

    NSArray *constraints2=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-hPadding-[_productNewLabel(==13)]" options:0 metrics:nil views:@{@"_productNewLabel":_productNewLabel,@"hPadding":@(hPadding)}];

    报错信息是这样的

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format: It's not possible to set a space equal to the width or height of a view. Perhaps you want to use a view as a spacer?

    其实报错信息说的很明白,就是我写了一个动态的间距hpadding,然后他没识别;

    看到这很多大神应该都明白了,因为我把hpaddingKeyValue加错地方了

    我加在了Views里面,其实应该加在metrics就对啦,还是stackoverflow比较强大呀。最后在里面搜到的答案

    NSArray *constraints2=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-hPadding-[_productNewLabel(==13)]" options:0 metrics:@{@"hPadding":@(hPadding)} views:@{@"_productNewLabel":_productNewLabel}];

    以上就对啦。

  • 相关阅读:
    PHP之get请求用php脚本实现
    PHP之download
    PHP之缩略图
    PHP之upload
    文本域<textarea>将 替换成换行
    JSON中获取变量key的值
    emap表格checkbox属性默认勾选
    读取ORACLE数据库中BOLB形式数据在前端预览
    oracle常用语法
    批量删除本地仓库未下载完成的jar文件
  • 原文地址:https://www.cnblogs.com/waiwaibuzhidao/p/6093587.html
Copyright © 2011-2022 走看看