0

我有一些按钮,我左对齐和换行标题文本。

当我运行该应用程序时,文本未格式化的位置存在延迟:

预格式化文本 http://imageshack.us/a/img28/1958/preformat.jpg

到对齐和换行生效的时间:

后格式文本 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;
4

0 回答 0