Search code examples
iosuibuttoninterface-builderaspect-ratioios-autolayout

incorrect content image with autolayout 3 uibutton same width proportionaly to width screen


I have 3 buttons which is have same width proportionally to width screen, and no constraint error,

(=leadingsuperview)button1(=HSpace)button2(=HSpace)button3(=trailingsuperview)

button2 same width to button 1

button3 same width to button 1

button1 center vertical to superview

button 2 and 3 center vertical to button 1

button1 height is proportional to its width 1:1 ratio

button2 and 3 is equal to height button1

Result:

3 buttons has correct frame (i know why it correct because i set background color to yellow and its true have same width)

but the incorrect part is, why just the 1st button images is smaller, the others button have correct size images.

already set at interfacebuilder like below:

[btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
[btn setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];

3 buttons have the same property,

but why just 1st button has incorrect images content, like it has been aspect fit for some reason (i didn't set aspect fit or whatsoever).

for more detail see these pictures below:

at interface-builder:

enter image description here

at compiled device:

enter image description here

Anybody has experienced this?

ps: for iOS >=8.4


Solution

  • I found out the solution:

    It is because I have custom class property that build in the runtime of interface builder.

    I forgot to remove the 1st button custom property, that explain why only 1st button is incorrect.