title: How do I define NSLayoutConstraint for a right alignment within a stack view?
body: <p>I am try to align an icon, some text, and a result within two stack views.</p>
  
  <p>The first stack view is vertical and contains X horizontal stack views. Each of the horizontal stack views contains a <code>UIImageView</code> and two <code>UILabel</code>s. </p>
  
  <p>While the <code>UIImageView</code> and the first <code>UILabel</code> should be aligned to the left, the last <code>UILabel</code> should align on the right side of the stack view.</p>
  
  <p>The whole UI is generated in code, in this case C# but I don't think it is hard to convert Swift code to C#. After reading a bit about iOS UI, I think I can solve this with <code>NSLayoutConstraint</code>, but I don't know how to use it — my current attempts always end in an exception.</p>
  
  <p>This is how I am setting my constraint currently:</p>
  
  <pre><code>dataStack.Constraints.Append(NSLayoutConstraint.Create(percentageLabel, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, dataStack, NSLayoutAttribute.Leading, 1, 0));
  </code></pre>
  
  <p><strong>Edit:</strong>
  This is how it currently look like: <a href="https://puu.sh/Ddlrx/ab36d7c864.png" rel="nofollow noreferrer">https://puu.sh/Ddlrx/ab36d7c864.png</a> but the percentage should be right aligned so each line ends at the same place. </p>
  
  <p>And this is my current code which generates the UI: <a href="https://pastebin.com/pvMTGx0U" rel="nofollow noreferrer">https://pastebin.com/pvMTGx0U</a> </p>
  
  <p>The constraints in the current code are a 1:1 copy of a working implementation in XCode Designer... I don't get it why it won't work this way in my widget. :/</p>