-1

Say I have to update a label 1000 times a minute. Completely change its string value. Am I best off making 1000 setText: calls per minute? Or is there a more efficient way? Perhaps doing away with labels completely?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Doug Smith
  • 29,668
  • 57
  • 204
  • 388

3 Answers3

1

You basically have two options - update the textproperty of a UILabel or draw an NSString directly onto a UIView (after first erasing the previous value). You'll have to run some tests to see which is more efficient.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
0

You can update some local field/variable and use Timer which read value from variable as frequent as it necessary and update Label. You can also use some throttle strategies. I'm not an iOS expert so I say what my intuition says to me.

szogun1987
  • 627
  • 6
  • 14
0

I've used this github library in one of my projects https://github.com/dataxpress/UICountingLabel, which basically subclasses a UILabel and counts down from some initial value to some final value with a custom duration that you can specify, and it is quite efficient and smooth. You can have a look at their code and it might help.

Dhruv Goel
  • 2,715
  • 1
  • 17
  • 17