Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9213455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:45:14+00:00 2026-06-18T01:45:14+00:00

I regularly use lazy loading to instantiate custom classes, arrays, etc. The pattern is

  • 0

I regularly use lazy loading to instantiate custom classes, arrays, etc. The pattern is typically:

@property (strong, nonatomic) Class *class;

...

- (Class *)class
{
    if(!_class) _class = [[Class alloc]init];
    return _class;
}

Is it possible to use the same pattern to configure UI elements? For example, instead of formatting all my buttons and views in ViewWillAppear, I would like to put the formatting in the getter. For example:

- (UIButton *)button
{
    if(!_button) {
        _button = [[UIButton alloc]init];
        self.button.backgroundColor = [UIColor redColor];
    }
    return _button;
}

The problem is I am using a storyboard and XCode instantiates the button so asking if it is nill should always return false. So the background will never be changed. If I remove the if-then, then the background will be set every time the getter is accessed which is probably OK but not optimal.

So, how do I use a UI element’s getter to configure the element?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:45:16+00:00Added an answer on June 18, 2026 at 1:45 am

    If this is really the way you want to do it, just use a BOOL flag. For example:

    @interface MyClass() {
    
        BOOL _hasCustomisedButton;
    }
    
    @property (strong, nonatomic) UIButton *button;
    
    @end
    
    @implementation MyClass
    
    
    - (UIButton *)button {
    
        if (_hasCustomisedButton || _button == nil) {
            // check for nil button as well in case the nib isn't loaded yet
            return _button;
        }
    
        [_button setBackgroundColor:[UIColor redColor]];
    
        _hasCustomisedButton = YES;
    
        return _button;
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I regularly use the jQuery jScrollPane plugin to add custom scroll bars to page
In the past I have created ItemTemplates for classes that I regularly use in
I use CSS transitions fairly regularly and for some reason I cannot get them
I have a WinForms utility that I use constantly, and enhance regularly. Roughly one
How to use regular expression in prev()? <div class=aaa>aaa</div> <div style=display: none class=bbb>bbb</div> <div
In my bash scripts, I regularly use file paths which may contain spaces: FOO=/path\
I regularly use a standard form to send login information through the HTTP POST
I have bash script that I use regularly in my job to automate a
I regularly use shallow routes on nested resources , so thought I missed something
I just realized all the data structures I regularly use are really old and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.