GBFlatButton icon indicating copy to clipboard operation
GBFlatButton copied to clipboard

Button disappears if I use a horizontal centering layout constraint

Open chadpod opened this issue 7 years ago • 5 comments

Button renders fine if I set leading and trailing layout constraints, but anytime I try to use a width layout constraint with a horizontal centering constraint (either to its superview or relative to another element) the button fails to render at all? Any ideas?

The button still functions ... it just isn't visible at all.

Change the class to a UIButton with no other changes and it renders fine.

chadpod avatar Sep 01 '16 19:09 chadpod

Couldn't tell you why, but the issue appears to lie with 'customizeAppearance'. When a horizontal centering layout constraint is used, customizeAppearance is called before frames and bounds are set properly. Moving the entire body of customizeAppearance into drawRect (there must be better solution) fixed the problem.

chadpod avatar Sep 01 '16 19:09 chadpod

Pretty sure this is a bug in auto layout as I'm seeing the same thing happen with a UIImageView in a completely different view hierarchy when a horizontal layout constraint is applied to it. The layout applied in Interface Builder causes the problem but same layout applied in code (in viewDidLoad of parent view controller) works fine.

chadpod avatar Sep 01 '16 19:09 chadpod

Did you ever track this issue down? I have the same issue. Moving customizeAppearance code to drawRect solved it for me, but seems like there must be a cleaner way to fix it.

toddfreese avatar Oct 14 '16 17:10 toddfreese

I never did. After looking into it further, I was under the impression it was an iOS auto layout bug, as a stock UIImageView was running into the same issue. Please let me know if you find out otherwise.

chadpod avatar Oct 14 '16 18:10 chadpod

Will do.

toddfreese avatar Oct 14 '16 18:10 toddfreese