I'm trying to anchor a sprite to the left side of the longest of two dynamic text strings.

I do this by calling SetAnchor(longestLabel) in code, however the sprite's position shifts at runtime when anchored to the top label. I believe this is because the Left, Right, Bottom & Top offsets are not being updated at runtime when SetAnchor() is called.
However the L, R, T & B offsets DO update automatically in the editor when dragging a new Target onto the anchor property. How do I replicate that behavior at runtime?
Or is there an easier way to accomplish what I'm trying to achieve?