Memory/performance trading question? [closed]
What is the best?
I want to handle about 400 buttons (the buttons have 4 state). What is the best? To store/display 4 different OPAQUE image for each button, or assamble the states from 2 ALPHA MASKED png?
I know that the question is a bit foggy. More OPAQUE 开发者_运维百科image, or less but ALPHA MASKED?
If there's any experience, please share.
As I mentioned before, I really don't think this would be a good idea (from an UX perspective). However, if you do want to do this, you should 'hack' a little bit to increase the performance.
Instead of using 400 (or even 400 * 4 = 1600
) UIView
s (or UIButton
s, which would basically be the same in this case), you should stick to one subclassed UIView
and override the drawRect:
method for faster and cached drawing.
You can override the touchesBegan ...
, touchesMoved ...
, etc. events to track touch events. When a user presses one 'button' (actually, it presses in your single view, but you can measure in what button it'ld be), you update a single int
-variable and call setNeedsDisplay
to redraw the 'buttons'.
That depends on where exactly you'll be using them. If we are talking about static positions - use alpha masked. On tables(and any scroll enabled views) you need to check performance first.
精彩评论