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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:54:48+00:00 2026-05-22T18:54:48+00:00

hey people, I try to add a nice gradient to a UIButtonTypeRoundedRect. the following

  • 0

hey people,
I try to add a nice gradient to a UIButtonTypeRoundedRect. the following code is implemented in the

viewWillAppear:(BOOL)animated   

function of my view controller.

UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
tempButton.frame = CGRectMake(left, top, 80.0f, 80.0f); 

CAGradientLayer * hintergrundButtonLayer = [[CAGradientLayer alloc] init];
[hintergrundButtonLayer setBounds:tempButton.bounds];
[hintergrundButtonLayer setColors:[NSArray arrayWithObjects: 
                   [UIColor colorWithRed:0.2 green:0.3 blue:0.4 alpha:1.0],
                   [UIColor colorWithRed:0.4 green:0.5 blue:0.6 alpha:1.0], 
                   nil]];

[hintergrundButtonLayer setPosition: 
             CGPointMake([tempButton bounds].size.width/2, 
                         [tempButton bounds].size.height/2)];

[hintergrundButtonLayer setLocations:
                       [NSArray arrayWithObjects:
                              [NSNumber numberWithFloat:0.0], 
                              [NSNumber numberWithFloat:1.0], 
                              nil]];

//      hintergrundButtonLayer.zPosition = -10;
//      hintergrundButtonLayer.frame = [tempButton bounds];


[tempButton addTarget:self action:@selector(switchVendorOnOff:) forControlEvents:UIControlEventTouchUpInside];


CALayer * downButtonLayer = [tempButton layer];
[downButtonLayer setMasksToBounds:YES];
[downButtonLayer setCornerRadius:10.0];
[downButtonLayer setBorderWidth:1.2];
[downButtonLayer setBorderColor:[[UIColor blackColor] CGColor]];


[downButtonLayer addSublayer:hintergrundButtonLayer];

[hintergrundButtonLayer release];
hintergrundButtonLayer = nil;

[self.view addSubview:tempButton];

the code runs fine until the app tries to display the view – it crashs with a EXC_BAD_ACCESS. But if I comment out the

[downButtonLayer addSublayer:hintergrundButtonLayer];   

command, then everything is fine.

The debugger tells me nothing about leaks. Also the allocation template shows nothing strange. There is nothing else printed to the console than the EXC_BAD_ACCESS message. The “build and analyse” shows no errors.

Does anyone see my problem?

  • 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-22T18:54:49+00:00Added an answer on May 22, 2026 at 6:54 pm

    setColors takes CGColors, not UIColors.

    [hintergrundButtonLayer setColors:[NSArray arrayWithObjects: 
        [[UIColor colorWithRed:0.2 green:0.3 blue:0.4 alpha:1.0] CGColor],
        [[UIColor colorWithRed:0.4 green:0.5 blue:0.6 alpha:1.0] CGColor], 
        nil]];
    

    If you read the top stack frames in the crash (while running under the debugger), they suggest a problem with CGColors:

    (gdb) bt
    #0  0x00bd407c in CGColorSpaceGetMD5Digest ()
    #1  0x00b4f8b2 in CGColorTransformConvertColorFloatComponents ()
    #2  0x00b4fea2 in CGColorTransformConvertColorComponents ()
    #3  0x00cb0d62 in CA_CGColorGetRGBComponents ()
    #4  0x00d509aa in -[CAGradientLayer _copyRenderLayer:layerFlags:commitFlags:] ()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey people, i have a the following map* which is giving me lots of
Hey people, why won't this code work? The Facebook API is so bad it's
Hey people yesterday i was working on some code and thought that i would
hey people kindly tell me if the following declaration is correct? if it is
hey people I'm new at jquery and i have been trying to figure this
Hey, I'm using a html form that is used to log people into my
Hey, I was working with a PHP function that takes multiple arguments and formats
hey people hope all is well.. i am trying to create a form in
hey people im having trouble with loading my array of strings into a tableview
I really like the idea of reading others people code to improve your design

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.