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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:25:25+00:00 2026-05-30T17:25:25+00:00

I have a UIView Subclass that has a frame/image with buttons in it. I’m

  • 0

I have a UIView Subclass that has a frame/image with buttons in it. I’m trying to add it to my view controller however when I do it shows up but none of the buttons will register ANY touches.

Here is my UIView Subclass.

    #import "ControlView.h"

@implementation ControlView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        CGRect slideFrame = CGRectMake(0, 402, 320, 82);
        slider = [[UIView alloc] initWithFrame:slideFrame];
        slider.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"shelf.png"]];
        [self addSubview:slider];

        UIImage *btnImage = [UIImage imageNamed:@"NavBar_01.png"];
        UIImage *btnImageSelected = [UIImage imageNamed:@"NavBar_01_s.png"];

        btnImage = [UIImage imageNamed:@"NavBar_01.png"];
        btnImageSelected = [UIImage imageNamed:@"NavBar_01_s.png"];
        btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn1.frame = CGRectMake(12, 28, 70, 50);
        [btn1 setBackgroundImage:btnImage forState:UIControlStateNormal];
        [btn1 setBackgroundImage:btnImageSelected forState:UIControlStateSelected]; 
        [slider addSubview:btn1];
        [slider bringSubviewToFront:btn1];
        [btn1 addTarget:self action:@selector(home) forControlEvents:UIControlEventTouchUpInside];

        btnImage = [UIImage imageNamed:@"NavBar_02.png"];
        btnImageSelected = [UIImage imageNamed:@"NavBar_02_s.png"];
        btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn2.frame = CGRectMake(87, 28, 70, 50);
        [btn2 setBackgroundImage:btnImage forState:UIControlStateNormal];
        [btn2 setBackgroundImage:btnImageSelected forState:UIControlStateSelected]; 
        [slider addSubview:btn2];
        [slider bringSubviewToFront:btn2];
        // [btn2 addTarget:self action:@selector() forControlEvents:UIControlEventTouchUpInside];

        btnImage = [UIImage imageNamed:@"NavBar_03.png"];
        btnImageSelected = [UIImage imageNamed:@"NavBar_03_s.png"];
        btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn3.frame = CGRectMake(162, 28, 70, 50);
        [btn3 setBackgroundImage:btnImage forState:UIControlStateNormal];
        [btn3 setBackgroundImage:btnImageSelected forState:UIControlStateSelected]; 
        [slider addSubview:btn3];
        [slider bringSubviewToFront:btn3];
        // [btn3 addTarget:self action:@selector() forControlEvents:UIControlEventTouchUpInside];

        btnImage = [UIImage imageNamed:@"NavBar_04.png"];
        btnImageSelected = [UIImage imageNamed:@"NavBar_04_s.png"];
        btn4 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn4.frame = CGRectMake(237, 28, 70, 50);
        [btn4 setBackgroundImage:btnImage forState:UIControlStateNormal];
        [btn4 setBackgroundImage:btnImageSelected forState:UIControlStateSelected]; 
        [slider addSubview:btn4];
        [slider bringSubviewToFront:btn4];
        // [btn4 addTarget:self action:@selector() forControlEvents:UIControlEventTouchUpInside];

        UISwipeGestureRecognizer *recognizer;

        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideUp)];
        [recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
        [self addGestureRecognizer:recognizer];

        recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(slideDown)];
        [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
        [self addGestureRecognizer:recognizer];

    }
    return self;
}

-(void)slideUp
{
    // Slide up based on y axis
    CGRect frame = slider.frame;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.75];
    frame.origin.y = 320;
    slider.frame = frame;
    [UIView commitAnimations];  
}

-(void)slideDown
{
    CGRect frame = slider.frame;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.75];
    frame.origin.y = 425;
    slider.frame = frame;
    [UIView commitAnimations];  
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end

And this is how I’m adding it to my ViewController.

 ControlView *cont = [[ControlView alloc]init];
    [homeView.view addSubview:cont];

I tried adding the same code to a ViewController and the buttons etc.. worked so I’m sure this is something simple/stupid with Delegates/Self etc.. between the subview and the ViewController however I have a mental block.

  • 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-30T17:25:27+00:00Added an answer on May 30, 2026 at 5:25 pm

    You are doing this?

     ControlView *cont = [[ControlView alloc]init]; 
    

    you are supposed to do

    ControlView *cont = [[ControlView alloc]initWithFrame:self.view.frame];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a UIView subclass that has a border image, but I
I have a UIView subclass ( CustomView for purposes of this question) that has
I have a custom UIView subclass that i'm trying to use as a header
I have a UIView subclass that draws a curved line within it's frame (using
I have a UIView subclass that has the following in drawRect: for(int j=0; j<[myArray
I have a UIView subclass that draws itself when -drawRect: is called. It only
If I have a UIView (or UIView subclass) that is visible, how can I
Currently, I have a UIView subclass that stamps a single 2px by 2px CGLayerRef
I have a subclass s of UIView. I want to put some buttons and
I have a UIView subclass. This subclass has multiple subviews. Is it possible to

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.