iphone - What is the correct way to re-use UILabel's style? -


i have several uilabels have same visual treatment. instead of redefining every single property every time, thinking of making copies of instance , changing text. how should done?

another way create factory method, i'm not fond of idea.

if you're willing learn three20, use ttlabel class, incorporated three20's stylesheet system, designed solve problem. however, have had trouble parsing three20's so-called documentation, think learning use library solve problem lot of overhead.

my work-around problem put mini factory method, this:

// example: - (uilabel *)makelabel {   uilabel *label = [[[uilabel alloc] init] autorelease];   label.backgroundcolor = [uicolor clearcolor];   label.font = [uifont systemfontofsize:kmyfontsize];   label.textcolor = [uicolor bluecolor];   label.textalignment = uitextalignmentcenter;   [self.view addsubview:label];   return label; } 

then when use method, other code gets cleaner:

uilabel *namelabel = [self makelabel]; namelabel.text = username; uilabel *titlelabel = [self makelabel]; titlelable.text = mytitle; // both labels have consistent style. 

pengone suggests subclassing uilabel. that's option, although think factory method job less work.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -