Note that there are some explanatory texts on larger screens.

plurals
  1. POios: UIButton title format delay
    text
    copied!<p>I've got some buttons where I left align and line wrap the title text. </p> <p>When I run the app, there is a delay from where the text is unformatted:</p> <p><a href="http://imageshack.us/a/img28/1958/preformat.jpg" rel="nofollow noreferrer">pre-format text http://imageshack.us/a/img28/1958/preformat.jpg</a></p> <p>To when the alignment and wrapping take effect:</p> <p><a href="http://imageshack.us/a/img821/6118/postformat.jpg" rel="nofollow noreferrer">post-format text http://imageshack.us/a/img821/6118/postformat.jpg</a></p> <p>On the simulator the delay is quite noticeable (~ 1 second), on my mate's iPhone 5 the delay is much smaller but still noticeable. </p> <p>What causes this delay? Can I get around this delay?</p> <p>Thanks in advance!</p> <hr> <p><strong>EDIT</strong><br><br> In my viewDidLoad method I create 10 buttons:</p> <pre><code>for (int i = 1; i &lt;= STEP_NUMBER; ++i) [self createStepButtion:i isIphone:isIphone isRetina:isRetina]; </code></pre> <p>In createStepButton, the relevant code is below:</p> <pre><code>UIButton * b = [UIButton buttonWithType:UIButtonTypeCustom]; // Listener [b addTarget:self action:@selector(goToStep:) forControlEvents:UIControlEventTouchUpInside]; [self.scrollView addSubview:b]; // Set button size. CGFloat width = self.scrollView.frame.size.width; // CGRectMake(x, y, width, height) int y = stepNum * margin + (stepNum - 1) * buttonHeight; int buttonWidth = width - margin * 2; b.frame = CGRectMake(margin, y, buttonWidth, buttonHeight); b.layer.cornerRadius = cornerRadius; b.clipsToBounds = YES; b.showsTouchWhenHighlighted = YES; // Image [b setImage:img forState:UIControlStateNormal]; b.imageEdgeInsets = [self makeImageInsets:buttonWidth]; // Text [b setTitleEdgeInsets:UIEdgeInsetsMake(0, titleLeftMargin, 0, titleRightMargin)]; b.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; b.titleLabel.lineBreakMode = UILineBreakModeWordWrap; [b setTitle:[NSString stringWithFormat:@"%i - %s", stepNum, STEP_NAMES[stepNum - 1]]forState:UIControlStateNormal]; [b setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; b.titleLabel.font = [UIFont systemFontOfSize:fontSize]; // Background [b setBackgroundColor:[UIColor whiteColor]]; // The step number this button represents. b.tag = stepNum; </code></pre>
 

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