我有一些按钮,我保持对齐并换行标题文字。
当我运行应用程序时,文本未格式化的时间会延迟:
pre-format text http://imageshack.us/a/img28/1958/preformat.jpg
当对齐和包装生效时:
post-format text http://imageshack.us/a/img821/6118/postformat.jpg
在模拟器上,延迟非常明显(约1秒),在我的队友的iPhone 5上,延迟要小得多,但仍然很明显。
导致这种延迟的原因是什么?我能解决这个延迟吗?
提前致谢!
修改
在我的viewDidLoad方法中,我创建了10个按钮:
for (int i = 1; i <= STEP_NUMBER; ++i)
[self createStepButtion:i isIphone:isIphone isRetina:isRetina];
在createStepButton中,相关代码如下:
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;