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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:08:11+00:00 2026-05-15T00:08:11+00:00

My custom subclass extend UIControl (EditableImageView) Basically it contains 3 subviews: UIButton (UIButtonTypeCustom) UIImageView

  • 0

My custom subclass extend UIControl (EditableImageView)
Basically it contains 3 subviews:

  • UIButton (UIButtonTypeCustom)
  • UIImageView
  • UILabel

All the class works great but now I want to connect some events generated from this class to another. In particular when the button is pressed I want to forward the event to the owner viewcontroller so that I can handle the event. The problem is that I can’t figure out how to implement this behaviour.
Within EditableImageView I can catch the touch event using [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside] but I don’t know how to forward it inside of the buttonPressed selector.
I also tried to implement touchesBegan but it seems never called…

I’d like to capture the button press event from the viewcontroller in this way:

- (void)viewDidLoad {
[super viewDidLoad];

self.imageButton = [[EditableImageView alloc] initWithFrame:CGRectMake(50.0f, 50.0f, 80.0f, 80.0f)];
[imageButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:imageButton];
[imageButton setEditing:NO];

}

This is my UIControl subclass initialization method:

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setBackgroundColor:[UIColor clearColor]];

        button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height);
        [button setImage:[UIImage imageNamed:@"nene_70x70.png"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

        [self addSubview:button];

        transparentLabelBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"editLabelBackground.png"]];
        transparentLabelBackground.hidden = YES;
        [self addSubview:transparentLabelBackground];

        // create edit status label
        editLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        editLabel.hidden = YES;
        editLabel.userInteractionEnabled = NO;  // without this assignment the button will not be clickable
        editLabel.textColor = [UIColor whiteColor];
        editLabel.backgroundColor = [UIColor clearColor];
        editLabel.textAlignment = UITextAlignmentLeft;
        UIFont *labelFont = [UIFont systemFontOfSize:16.0];
        editLabel.font = labelFont;     
        editLabel.text = @"edit"; 
        labelSize = [@"edit" sizeWithFont:labelFont];

        [self addSubview:editLabel];
    }

    return self;
}

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-15T00:08:12+00:00Added an answer on May 15, 2026 at 12:08 am

    I solved in this way:

    EditableImageView.h:

    @interface EditableImageView : UIControl {
    UIButton *button;
    UIImageView *transparentLabelBackground;
    UILabel *editLabel;
    CGSize labelSize;
    
    BOOL editing;
    }
    
    @property (nonatomic, retain) UIButton *button;
    @property (nonatomic, retain) UILabel *editLabel;
    @property (nonatomic, retain) UIImageView *transparentLabelBackground;
    @property (nonatomic, getter=isEditing) BOOL editing;
    
    - (void)buttonPressed:(id)sender;
    @end
    

    EditableImageView.m:

     (id)initWithFrame:(CGRect)frame {
        if (self = [super initWithFrame:frame]) {
            [self setBackgroundColor:[UIColor clearColor]];
    
            button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(0.0f, 0.0f, frame.size.width, frame.size.height);
            [button setImage:[UIImage imageNamed:@"nene_70x70.png"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
            .......
        }
    }
    
    
    - (void)buttonPressed:(id)sender {
    [self sendActionsForControlEvents:UIControlEventTouchUpInside];
    }
    

    MyController.m:

    - (void)viewDidLoad {
        [super viewDidLoad];
        self.imageButton = [[EditableImageView alloc] initWithFrame:CGRectMake(50.0f, 50.0f, 80.0f, 80.0f)];
        [imageButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:imageButton];
    }
    
    - (void)buttonPressed:(id)sender {
        NSLog(@"buttonPressed!");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a custom UITableViewCell subclass which contains a button named testbtn . I
I have a custom UIViewController subclass that handles all the view initialization by itself
I have a custom UIComponent that is basically just this: public class WhiteboardUIComponent extends
I have a custom subclass of UILabel which makes custom drawing using CoreText. I
I have a custom subclass of AlertDialog that should display a list of all
i would like to create a custom View (subclass of the View class) and
I've created a custom subclass of UIImageView and in one method I want to
I have created a custom subclass of UITableViewCell. There, I allow the user to
Similar to this question I have a custom subclass of UITableViewCell that has a
I'm writing a unit test for a custom subclass of org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter<T> and I need

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.