I have a UISprite (that is also a UIButton) that I am dynamically instantiating as a child of a scroll view / UI grid. I've set the anchor for the scroll view to be the width of it's container so it expands horizontally. The UISprite/Button is a prefab, which can't store it's anchor until it knows what it's parent is.
mySprite.leftAnchor.target = transform.parent;
mySprite.leftAnchor.absolute = 17;
mySprite.rightAnchor.target = transform.parent;
mySprite.rightAnchor.absolute = -17;
mySprite.ResetAnchors();
is the code I'm using to try and anchor the UISprite/Button to it's parent (the scrollview). However, for some reason I look at the scene after that code has run and the anchors for all those sprite-buttons is None.
Any idea what I'm doing wrong?