I just came to this post in 2015 and I wasn't satisfied with the answers here.
Here's my solution. Change the 4
for as many dots as you want. This will do 3 dots (4 - 1
). Change the word Posting
to whatever status you need.
First add a timer as stated above.
self.ellipsisTimer = [NSTimer scheduledTimerWithTimeInterval:0.6
target:self
selector:@selector(updateLabelEllipsis:)
userInfo:nil
repeats:YES];
In your update method:
- (void) updateLabelEllipsis:(NSTimer *)timer {
NSString *messageText = [[self messageLabel] text];
NSInteger dotCount = messageText.length - [[messageText stringByReplacingOccurrencesOfString:@"." withString:@""] length] + 1;
[[self messageLabel] setText:@"Posting"];
NSString *addOn = @".";
if (dotCount < 4) {
addOn = [@"" stringByPaddingToLength:dotCount withString: @"." startingAtIndex:0];
}
[[self messageLabel] setText:[[[self messageLabel] text] stringByAppendingString:addOn]];
}
It works by counting the current number of dots and adding one more. Once it goes above the limit it goes back to 1 dot.