Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you enter a constraint value with decimal in IB?

Here is to hoping it is a simple setting.

I cannot enter a constraint value with decimals in IB. Whenever I enter a value with decimals and press enter, the system rounds it!

I don't have this problem when creating constraints in code. Only in IB.

Is there a way?

like image 903
Khaled Barazi Avatar asked Dec 16 '14 08:12

Khaled Barazi


2 Answers

Yes, you can.

  1. Enter the value with a "f" postfix like this: enter image description here

  2. Click Priority. notice how the effective constraint value changes to 0.5: enter image description here

  3. Hit ESC
like image 183
AmitP Avatar answered Sep 22 '22 22:09

AmitP


It has to be done programmatically, I believe. As of Xcode 6.3, constraint constant values seem to be restricted to integers in the storyboard editor (unlike multiplier values, which can be decimals).

For Googlers, here's how to do it:

To specify a decimal value for a constraint defined in a storyboard, you can set the constant property of a constraint iVar. Here's an example of setting a height constraint to 0.5f:

In your header:

@property (nonatomic, retain) IBOutlet NSLayoutConstraint *separatorHeightConstraint;

then connect the IBOutlet to the constraint in the storyboard.

In your implementation:

-(void)layoutSubviews {
    [super layoutSubviews];
    self.separatorHeightConstraint.constant = 0.5f;
}

That's all!

like image 36
adamup Avatar answered Sep 24 '22 22:09

adamup