Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>To set the alignment of a <code>UIButton</code></strong>, look in the Attributes Inspector in Interface Builder for the button. There's a section called Alignment. Set it to left. Or right, or whatever you want.</p> <p><img src="https://i.stack.imgur.com/XcuVF.jpg" alt="enter image description here"></p> <p>To do it in code, use the <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIControl_Class/Reference/Reference.html#//apple_ref/occ/instp/UIControl/contentHorizontalAlignment" rel="noreferrer"><code>contentHorizontalAlignment</code></a> property of <code>UIControl</code>. You can set it to any of these properties:</p> <p><code>UIControlContentHorizontalAlignmentCenter</code><br> <code>UIControlContentHorizontalAlignmentLeft</code><br> <code>UIControlContentHorizontalAlignmentRight</code><br> <code>UIControlContentHorizontalAlignmentFill</code> </p> <pre><code>[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]; </code></pre> <p>None of these options look particularly good (as you can see above), and you might have might have more luck using the <code>contentEdgeInsets</code> property of <code>UIButton</code> to reposition the content.</p> <p><strong>To set a multiline title</strong> on a <code>UIButton</code>, <a href="http://unsolicitedfeedback.com/?p=59" rel="noreferrer">check this forum post</a> which describes changing the button label. </p> <p>Or you can use this code to quickly make a 2 line button:</p> <pre><code>myButton.titleLabel.textAlignment = UITextAlignmentCenter; myButton.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap; [myButton setTitle:@"Siegfried\nRoy" forState:UIControlStateNormal]; </code></pre> <p><img src="https://i.stack.imgur.com/jR4ac.png" alt="enter image description here"></p> <p>Raju, don't forget to mark questions as accepted.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload