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

  • Home
  • SEARCH
  • 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 6055289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:14:55+00:00 2026-05-23T08:14:55+00:00

I can’t figure out how I’m supposed to initialize this custom class, the code

  • 0

I can’t figure out how I’m supposed to initialize this custom class, the code isn’t mine and I’m fairly new to Obj-C, so I’m slow on the uptake.

PFTintedButton.h

#import <UIKit/UIKit.h>
@class CALayer;

typedef enum
{
    PFTintedButtonRenderTypeStandard,
    PFTintedButtonRenderTypeCandy,
    PFTintedButtonRenderTypeOpal,
} PFTintedButtonRenderType;


@interface PFTintedButton : UIButton
{
@private
    UIColor * tint;
    CGFloat cornerRadius;
    PFTintedButtonRenderType renderType;

    UIImage * stretchImage;
    CALayer * glowLayer;

    UILabel * subLabel;

    BOOL customShadow;
    BOOL customTitleColor;
}

@property( nonatomic, retain ) UIColor * tint;
@property( nonatomic, assign ) CGFloat cornerRadius;
@property( nonatomic, assign ) PFTintedButtonRenderType renderType;
@property( nonatomic, readonly ) UILabel * subLabel;



@end

PFTintedButton.m excerpt

#import "PFTintedButton.h"
#import "PFDrawTools.h"
#import "UIColor+PFExtensions.h"
#import <QuartzCore/QuartzCore.h>

#define glowRadius      30

@interface PFTintedButton()
-(void) createBackgroundImage;
-(void) createGlowLayer;
@end


@implementation PFTintedButton

-(void) dealloc 
{
    SafeRelease( tint );
    SafeRelease( stretchImage );
    SafeRelease( subLabel );
    SafeRelease( glowLayer );

    [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(createGlowLayer) object: nil];
    [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(renderGlowLayerOnMainThread) object: nil];

    [super dealloc];
}

-(void) initCommon
{
    cornerRadius = 6;
}

-(id) initWithFrame: (CGRect) frame 
{
    if( self = [super initWithFrame: frame] ) 
    {
        [self initCommon];
    }

    return self;
}

-(id) initWithCoder: (NSCoder *) coder 
{
    if( self = [super initWithCoder: coder] ) 
    {
        // this is such a hack but there's no other way to determine if the title label's settings
        // have been modified in IB.
        NSDictionary * dic = [coder decodeObjectForKey: @"UIButtonStatefulContent"];
        NSObject * st = [dic objectForKey: [NSNumber numberWithInt: UIControlStateNormal]];
        NSString * bc = [st description];

        customTitleColor = [bc rangeOfString: @"TitleColor = UIDeviceRGBColorSpace 0.196078 0.309804 0.521569 1"].location == NSNotFound;
        customShadow = [bc rangeOfString: @"ShadowColor = UIDeviceRGBColorSpace 0.5 0.5 0.5 1"].location == NSNotFound;

        [self initCommon];

        //[super setBackgroundColor: [[UIColor redColor] colorWithAlphaComponent: .5]];
    }

    return self;
}

I just included a small bit of the implementation, the full source can be found here. As a part of this repository by Paul-Alexander.

I initialize it like this:

PFTintedButton* buttony = [PFTintedButton buttonWithType:UIButtonTypeCustom];
[buttony setTint:[UIColor redColor]];
[buttony setBackgroundColor:[UIColor redColor]];
[buttony setRenderType:PFTintedButtonRenderTypeCandy];
[buttony setTitle:@"Title for Button" forState:UIControlStateNormal];

And it hiccups in PFDrawTools, it seems the tint variable is nil. So is it because I am initializing it incorrectly? Has anyone had success with this?

  • 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-23T08:14:55+00:00Added an answer on May 23, 2026 at 8:14 am

    It seems to explicitly handle initWithFrame, I would try that.

    PFTintedButton *buttony = [[[PFTintedButton alloc] initWithFrame:<some_frame>] autorelease];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can anyone help me trying to find out why this doesn't work. The brushes
can any one tell me how can change this java code into objective c.is
Can this line of code be made more compact? db_tables_scanned = {} IO.readlines(resume_log_file).each {
Can someone maybe tell me why this is not working? I have used echo
Can i get the source code for a WAMP stack installer somewhere? Any help
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Can somebody help me construct this regular expression, please... Given the following strings... "April
Can anyone tell me why this doesn't work? <?php $lang = $_get[lang]; if (($lang
Can we close all known/unknown connections to database with the code? I'm using Access

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.