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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:41:56+00:00 2026-06-09T09:41:56+00:00

I have made extension for UIButton class. Now if I use it everything works

  • 0

I have made extension for UIButton class. Now if I use it everything works good. But I have another class that create for me array with UIButton objects and here I have some problem.

I have Helper class with method that return for me array with UIButton objects.

In ViewController.m in viewDidLoad callback I request for this array and also here in ViewController.m I import my UIButton+Extension.m

So, now I have extension for each UIButton object that I will use in ViewController.m

But if I use extension I have got error on method that call

[thumbButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:11.0]];

but if I don’t use extension this method invoke correct.

this is my UIButton+Extension.h file

#import <UIKit/UIKit.h>

@interface UIButton (extension_button)

- (void)centerButtonToView:(UIView *)view;
- (UIImage *)cropeImage:(UIImageView *)imageView;

@end

this is my UIButton+Extension.m file

#import "UIButton+Extension.h"

@implementation UIButton (extension_button)

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)centerButtonToView:(UIView *)view {
    CGRect rect = view.frame;
    CGRect rectSelf = self.frame;
    rectSelf.origin.x = (rect.size.width / 2.0f - rectSelf.size.width / 2.0f) + rect.origin.x;
    rectSelf.origin.y = (rect.size.height / 2.0f - rectSelf.size.height / 2.0f) + rect.origin.y;
    self.frame = rectSelf;
}

- (UIImage *)cropeImage:(UIImageView *)imageView {    
    CGRect rect;
    rect.origin.x = self.frame.origin.x - imageView.frame.origin.x;
    rect.origin.y = self.frame.origin.y - imageView.frame.origin.y;
    rect.size.width = self.frame.size.width;
    rect.size.height = self.frame.size.height;    
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();    
    CGRect drawRect = CGRectMake(-rect.origin.x,-rect.origin.y, imageView.image.size.width, imageView.image.size.height);
    CGContextClipToRect(context, CGRectMake(0, 0, rect.size.width, rect.size.height));
    [imageView.image drawInRect:drawRect];
    UIImage* subImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return subImage; 
}

@end

Helper.m (method that return array for me and here I have problem on setFont method)

+ (NSMutableArray *)createThumbnailsForCropSize {

    CGFloat width = 0.0f;
    CGFloat start_pos = 0.0f;

    if (IS_IPHONE) {
        width = 320.0f;
        start_pos = 62.0f;
    }
    else {
        width = 768.0f;
        start_pos = 286.0f;
    }

    NSMutableArray *arr = [[NSMutableArray alloc] init];
    NSArray *resolutionArray = [NSArray arrayWithObjects:@"30x40",@"33x48",@"35x40",@"35x45",@"36x47",@"37x47",
                                @"40x50",@"40x60",@"43x55",@"45x50",@"50x50",@"50x70", nil];
    NSInteger pos_x = start_pos;
    NSInteger page = 0;
    for (NSInteger idx = 0; idx < 12; idx++) {
        if (idx%3 == 0 && idx != 0) {
            page++;
            pos_x = start_pos + width * page;
        }
        UIButton *thumbButton = [[UIButton alloc] init];
        [thumbButton setTag:idx];
        [thumbButton setFrame:CGRectMake(pos_x, 13, 60, 60)];
        [thumbButton setTitle:[NSString stringWithFormat:[resolutionArray objectAtIndex:idx]] forState:UIControlStateNormal];
        [thumbButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:11.0]];
        [thumbButton setTitle:@"!00" forState:UIControlStateNormal];
        [thumbButton setBackgroundImage:[UIImage imageNamed:@"block_without_photo.png"] forState:UIControlStateNormal];
        [arr addObject:thumbButton];
        pos_x += 68;
    }
    return arr;
}
  • 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-09T09:41:59+00:00Added an answer on June 9, 2026 at 9:41 am

    You need to remove initWithFrame: from your category. By including it, you are removing the normal implementation, and this will be preventing your buttons from being created properly, you will in fact be returning a UIControl.

    Calling the super implementation in a category does not call UIButton‘s implementation, but the superclass of UIButton – UIControl. Categories are different to subclasses. (And you shouldn’t subclass UIButton either, as it is a class cluster).

    If you do have specialist initialisation code in there, you will have to add it to a separate method and call it during your creation loop.

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

Sidebar

Related Questions

I have made a String[] array by using String.split(.) . I am now trying
I made a simple extension of CheckBoxPreference so that I could have my own
Now that we have extension methods in C#, Is there any point left in
I used to have an extension which made it so that when you hover
I have a database class that I made that uses PDO to connect to
I have made my custom In extension method as shown below: public static class
I have a shell extension made in .NET that creates folders (think of it
I have made a function that so far seems to be really good at
I have made a jQuery toggle for a menu that I had in mind.
i have made an application having entity framewrok. It is wpf application, now it

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.