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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:43:28+00:00 2026-05-25T01:43:28+00:00

I made a subclass of UIView that has a fixed frame. So, can I

  • 0

I made a subclass of UIView that has a fixed frame. So, can I just override init instead of initWithFrame:? E.g.:

- (id)init {
    if ((self = [super initWithFrame:[[UIScreen mainScreen] bounds]])) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

The Xcode documentation for -initWithFrame: says: “If you create a view object programmatically, this method is the designated initializer for the UIView class. Subclasses can override this method to perform any custom initialization but must call super at the beginning of their implementation.”

What does “designated initializer” mean?

  • 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-25T01:43:29+00:00Added an answer on May 25, 2026 at 1:43 am

    The designated initializer is the one that all the other initializers must call. UIView and subclasses are a little unusual in that they’ve actually got two such initializers: -initWithFrame: and -initWithCoder:, depending on how the view is created. You should override -initWithFrame: if you’re instantiating the view in code, and -initWithCoder: if you’re loading it from a nib. Or, you could put your code in third method and override both those initializers such that they call your third method. In fact, that’s often the recommended strategy.

    So, for example, you might create a UIView subclass, ClueCharacter, that has its own initialization method: -initWithPerson:place:thing:. You then create your view like this:

    Obj-C:

    ClueCharacter *mustard = [[ClueCharacter alloc] initWithPerson:@"Col. Mustard"
                                                             place:kInTheStudy
                                                             thing:kTheRope];
    

    Swift:

    var mustard = ClueCharacter("Col. Mustard", place: kInTheStudy, thing: kTheRope)
    

    That’s fine, but in order to initialize the UIView part of the object, your method must call the designated initializer:

    Obj-C:

    -(id)initWithPerson:(NSString*)name place:(CluePlace)place thing:(ClueWeapon)thing
    {
        if ((self = [super initWithFrame:CGRectMake(0, 0, 150, 200)])) {
            // your init stuff here
        }
    }
    

    Swift:

    func init(name: String, place : CluePlace, thing : ClueWeapon)
    {
        if (self = super.init(CGRectMake(0, 0, 150, 200))) {
           // your init stuff here
        }
    }
    

    If you want to call your subclass’s initializer -init, that’s okay as long as you call -initWithFrame: in the implementation.

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

Sidebar

Related Questions

In my app, I made a subclass of UIView that I want to use
I made a UITableViewCell subclass, and now I want that subclass to be clever.
I made of subclass of UIView called Bubble using which i want to draw
I have a UIViewController subclass to control a UIView that I want to add
I made a subclass of CMFCCaptionBar in what has so far been a vain
I'm implementing a subclass of UIView that displays a gauge dial with a sprite
I have made a subclass of UIView and i'm trying to animate a property
I have made a UIViewController subclass without a .xib file, thinking I would not
I made a custom UITableView subclass and implemented this: - (void)scrollViewDidScroll:(UIScrollView *)scrollView { //
I have subclass of UINavigationBar . @interface MyNavigationBar : UINavigationBar Made some changes 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.