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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:58:25+00:00 2026-06-02T01:58:25+00:00

I am trying to create custom buttons for my views. Everything works well except

  • 0

I am trying to create custom buttons for my views. Everything works well except when rendering I am getting an exception being thrown regarding my colors. My class has 2 color properties:

@property (nonatomic, retain) UIColor* defaultBackground;
@property (nonatomic, retain) UIColor* clickedBackground;

One to represent the default rendering color and the other for when the user has it clicked. Inside my initWithFrame method I initialize the colors:

defaultBackground = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
clickedBackground = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0];

This is all well and good until I get to the rendering where it throws an exception when getting the CGColor:

if((self.state & UIControlStateHighlighted) == 0)
    {
        CGContextSaveGState(context);
        CGContextSetFillColorWithColor(context, defaultBackground.CGColor); //Crashes on this line
        ...

Here is the exception that I am getting:

2012-04-13 10:19:51.005 -[__NSMallocBlock__ CGColor]: unrecognized selector sent to instance 0x7d94d20
2012-04-13 10:19:51.072 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSMallocBlock__ CGColor]: unrecognized selector sent to instance 0x7d94d20'

Any ideas would be greatly appreciated.

  • 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-02T01:58:27+00:00Added an answer on June 2, 2026 at 1:58 am

    Change the two lines in your initWithFrame: as follows:

    self.defaultBackground = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
    self.clickedBackground = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0];
    

    The problem is that assigning an autoreleased UIColor object directly to an ivar results in a dangling pointer to a released object. An alternative is:

    defaultBackground = [[UIColor alloc] initWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
    clickedBackground = [[UIColor alloc] initWithRed:0.5 green:0.5 blue:0.5 alpha:1.0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a custom button where the foreColor is always crimson and
I'm trying to change the back button to a custom one. If I create
Im trying to create a custom version of the RequiredAttribute to replace the built
I'm trying to create a custom UIButton that should look like a UIButtonTypeRoundedRect. In
I'm trying to create a custom component with a collection property. However if I
I'm trying to create a custom MembershipProvider and I was wondering how I would
I am trying to create a custom property in a extended control, so that
I am trying to create a custom wpf control, I'm wondering how I can
I am trying to create a custom context processor which will render a list
I am trying to create a custom authentication scheme in ASP.NET MVC using form

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.