iOS autolayout 代碼,自定義間距
最近換了新的項目組,然后這個項目組是純代碼,然后我就開始試著用代碼去寫適配,結果學藝不精,遇到個閃退,搜了一下發(fā)現幾乎沒有人遇到這個問題,后來發(fā)現其實就是我自己太粗心了。
我是這樣寫的
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?
其實報錯信息說的很明白,就是我寫了一個動態(tài)的間距hpadding,然后他沒識別;
看到這很多大神應該都明白了,因為我把hpaddingKeyValue加錯地方了
我加在了Views里面,其實應該加在metrics就對啦,還是stackoverflow比較強大呀。最后在里面搜到的答案
NSArray *constraints2=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-hPadding-[_productNewLabel(==13)]" options:0 metrics:@{@"hPadding":@(hPadding)} views:@{@"_productNewLabel":_productNewLabel}];
以上就對啦。
浙公網安備 33010602011771號