【发布时间】:2015-05-01 20:16:30
【问题描述】:
我有一个宽度接近 100% 的 UILabel。文本居中对齐。
我有一些代码要附加或以其他方式演练省略号的添加。
但是,这会导致 UILabel 在动画发生时移动的问题。这是因为文本居中对齐。
我希望我的代码添加或以其他方式更新省略号,但不“移动” UILabel。
如果可以的话,我不想添加另一个标签,但如果这是唯一的解决方案,那就太酷了。
代码如下;
// This is a method inside a custom UILabel subclass
- (void)startProgressAnimationWithInterval:(NSTimeInterval)interval
{
self.isAnimatingProgress = YES;
NSString *singleDot = @".";
NSString *doubleDot = @"..";
NSString *tripleDot = @"...";
if (![self.text hasSuffix:tripleDot]) {
self.text = [self.text stringByAppendingString:tripleDot];
}
self.progressTimer = [NSTimer vic_scheduledTimerWithTimeInterval:interval userInfo:nil action:^(NSTimer *timer, NSInteger repeatIndex) {
if ([self.text hasSuffix:tripleDot]) {
self.text = [self.text stringByReplacingOccurrencesOfString:tripleDot withString:singleDot];
}
else if ([self.text hasSuffix:doubleDot]) {
self.text = [self.text stringByReplacingOccurrencesOfString:doubleDot withString:tripleDot];
}
else {
self.text = [self.text stringByReplacingOccurrencesOfString:singleDot withString:doubleDot];
}
}];
}
【问题讨论】:
标签: objective-c text uilabel text-alignment