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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:32:43+00:00 2026-05-12T20:32:43+00:00

Im extending the UIButton Class to be able to set the font and color

  • 0

Im extending the UIButton Class to be able to set the font and color of the UINavigationBarButton ( from this code example: switch on the code )

I goes like this:

@interface NavBarButtonGrey : UIButton 
-(id)init;

@end


@implementation NavBarButtonGrey

-(id)init {
if(self = [super init]) {
    self.frame = CGRectMake(0, 0, 49.0, 30.0);
    self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    UIImage *image = [UIImage imageNamed:@"greyNavButton.png"];
    UIImage *stretchImage = 
    [image stretchableImageWithLeftCapWidth:15.0 topCapHeight:0.0];
    [self setBackgroundImage:stretchImage forState:UIControlStateNormal];
    self.backgroundColor = [UIColor clearColor];
    [self setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.titleShadowOffset = CGSizeMake(0, -1);
    self.titleLabel.font = [UIFont boldSystemFontOfSize:13];
}

return self;
}
@end

This is ok, but of course not very flexible.
How do I incorporate using a typedef enum (like Apple does) for all the different
colors, fonts and sizes I would like my custom button to conform to.

The only thing I can get out of the interface files from UIKit is that it is done like this:

typedef enum {
RGCustomNavBarButtonStyleBlue,
RGCustomNavBarButtonStyleGrey,
RGCustomNavBarButtonStyleBlack,
RGCustomNavBarButtonStyleGreen,
RGCustomNavBarButtonStyleRed, 
} RGCustomNavBarButtonStyle;

How to get from that and into a working implementation that takes font, size, color etc. from the values of the enum through the constructor(initWithStyle)?

Does one overload constructors in Objective C? multiple constructors?

Hope it makes sense and thank you for any help given:)

  • 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-05-12T20:32:43+00:00Added an answer on May 12, 2026 at 8:32 pm

    You can have multiple constructors such as;

    -(MyClass) initWithFont: (UIFont) font;
    -(MyClass) initWithFonmt: (UIFont) font andColor: (UIColor) color;
    

    etc.

    Then call [super init] as the first line in each of your custom constructors.

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

Sidebar

Related Questions

Extending from this questions about locales And described in this question : What I
By extending class Vector, Java’s designers were able to create class Stack quickly. What
I'm extending a partial class that was generated from an Entity Framework domain service
I am extending a class defined in a library which I cannot change: public
I'm extending the functionality of a class with a subclass, and I'm doing some
I am extending a template class using C++ in Visual Studio 2005. It is
Extending a website I didn't build. I want to be able to call the
Extending methods to any instance is really easy: public static string LeaveJustNumbers(this string text)
Im extending a class (DirectoryServices.AccountManagement.Principal) and I need to assign a value to a
when extending a class, is it impossible to override a method without also matching

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.