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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:34:38+00:00 2026-05-16T15:34:38+00:00

I have a very simple subclass of UIButton: @interface MyButton : UIButton @end @implementation

  • 0

I have a very simple subclass of UIButton:

@interface MyButton : UIButton
@end

@implementation MyButton

- (id) initWithCoder:(NSCoder *)decoder
{
    if (!(self = [super initWithCoder:decoder]))
        return nil;

    NSLog(@"-[%@ initWithCoder:%@]", self, decoder);

    return self;
}

@end

In Interface Builder I add a UIButton, set its button type to Rounded Rect and its class identity to MyButton.

When running, I have the following log:

-[<MyButton: 0x5b23970; baseClass = UIButton; frame = (103 242; 114 37); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x5b23a90>> initWithCoder:<UINibDecoder: 0x6819200>]

but the button is not a round rect button anymore.

Observed on both iOS 3.2 and iOS 4.

Is this a bug or am I missing something obvious?

Create an instance of MyButton programmatically is not an acceptable answer, thanks.

  • 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-16T15:34:39+00:00Added an answer on May 16, 2026 at 3:34 pm

    Programmatically, you instantiate a button with +[UIButton buttonWithType:] which is actually a factory that returns a subclass of UIButton. So if you derive from UIButton you actually don’t derive from your round rect button class (UIRoundedRectButton) but from a generic button class. But you are not allowed to subclass from UIRoundedRectButton AFAIK since it’s an internal class.

    It seems to be problematic to derive from UIButton, I’ve seen a lot of people recommed to derive from UIControl instead and implement the drawing yourself.

    But you might find these articles helpful:

    How to override -drawrect in UIButton subclass?

    http://www.cocoabuilder.com/archive/cocoa/284622-how-to-subclass-uibutton.html

    http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/

    Also, I don’t know why you want to derive from UIButton, but if you want to do some customization that does not involve overwriting any other methods it might be helpful to use the fact that you can do something like this:

    - (id)initWithCoder:(NSCoder *)decoder {
       // Decode the frame
       CGRect decodedFrame = ...;
       [self release];
       self = [UIButton buttonWithType:UIButtonTypeRoundedRect];
       [self setFrame:decodedFrame];
       // Do the custom setup to the button
       return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Most likely you won't be able to change ownership of… May 16, 2026 at 5:29 pm
  • Editorial Team
    Editorial Team added an answer I generally do this conversion in my code primarily because… May 16, 2026 at 5:29 pm
  • Editorial Team
    Editorial Team added an answer Use std::fill. It would be better to use a std::vector… May 16, 2026 at 5:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a very simple subclass of UIViewController : @interface RoastChickenViewController : UIViewController {
I have a very simply subclass of UIButton that will fire off a custom
I have a very simple interface which needs to communicate between processes. It's currently
I have a very simple scenario, using NHibernate: one abstract base class animal; two
I have a very simple .NET commandline application that I want to port to
I have a very simple class public class Preferences { public bool RepeatInfinite {
I have a very simple class that opens a file and creates a memory
I have a very simple problem, but I'm looking for the 'best' solution to
I have a very simple linq query that gets data from two datatables (orderHeader
I have a very simple basic bar's graphic like this one but i want

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.