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 9054633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:44:12+00:00 2026-06-16T13:44:12+00:00

I have the same code in every ViewController, it sets the backgroundcolor of the

  • 0

I have the same code in every ViewController, it sets the backgroundcolor of the ViewControllers’ view and it changes the backbutton and the titleview of the navbaritem.
Is there a way to avoid this?

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 37, 24)];
[button setImage:[UIImage imageNamed:@"Navbar_BackButton.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(backButtonTabbed:) forControlEvents:UIControlEventTouchDown];
[button setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];

[navbarItem setLeftBarButtonItem:barButton];

[navbarItem setTitleView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Navbar_Title.png"]]];

[[self view] setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"Login_Background.png"]]];
  • 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-16T13:44:13+00:00Added an answer on June 16, 2026 at 1:44 pm

    It’s a perfect case for subclassing.

    Create a subclass of UIViewController which overrides the viewDidLoad method performing your code, and then make every other view controller that need such behavior a subclass of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are 5 websites in ASP.NET 2.0 which have the same code and database
I have this same code at the end of each view to go to
Trying to send a complex type between two systems that have the same code
I have the same block of code repeated with two different variables. This block
I have different urls that points to the same code www.url1.com www.url2.com I need
I have a Full and Lite applications that were built from the same code.
I have WPF Form which has many buttons with the same code. Appearance of
I am using JQGrid I have it on 2 domains (same code)... On domain
I have 2 websites, both with the same code which display a Jquery speedometer.
I wrote the following loop since I have to repeat the same/similar code 25

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.