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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:08:51+00:00 2026-06-12T07:08:51+00:00

I am trying to put a custom UIButton on a custom UIView but the

  • 0

I am trying to put a custom UIButton on a custom UIView but the UIButton is not appearing. Although when I try to print UISubViews of my UIView, it shows the UIButton object there.

Below is the piece of the code I am writing to put the button on my custom UIView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor blackColor];
        self.headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        self.headerLabel.backgroundColor = [UIColor clearColor];
        self.headerLabel.textColor = [UIColor whiteColor];
        self.headerLabel.font = [UIFont systemFontOfSize:kApplicationHeaderTextFont];
        [self addSubview:self.headerLabel];

        self.actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.actionButton.frame = CGRectZero;
        [self addSubview:self.actionButton];
    }
    return self;
}
- (void)drawRect:(CGRect)iTotalRect{
    if (self.actionButtonImage) {
        self.actionButton.frame = CGRectMake(self.frame.size.width - self.actionButtonImage.size.width - 10.0, self.frame.size.height / 2 - self.actionButtonImage.size.height / 2, self.actionButtonImage.size.width, self.actionButtonImage.size.height);
        [self.actionButton setImage:self.actionButtonImage forState:UIControlEventTouchUpInside];
    }

Anybody know what I am doing wrong?

  • 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-12T07:08:52+00:00Added an answer on June 12, 2026 at 7:08 am

    so I found what you need!!

    maybe this:

     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self 
               action:@selector(aMethod:)
     forControlEvents:UIControlEventTouchDown];
    [button setTitle:@"Show View" forState:UIControlStateNormal];
    button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
    [view addSubview:button];
    

    and now u can add your options! try it!

    here is something from part of my app that u can see what i mean:

    - (void)addMyButton{    // Method for creating button, with background image and other properties
    
        UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
        playButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);
        [playButton setTitle:@"Play" forState:UIControlStateNormal];
        playButton.backgroundColor = [UIColor clearColor];
        [playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
        UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"];
        UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
        [playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
        UIImage *buttonImagePressed = [UIImage imageNamed:@"whiteButton.png"];
        UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
        [playButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
        [playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:playButton];  
    }
    

    well I found the final solution for you:

    UIButton *btnTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    btnTwo.frame = CGRectMake(40, 140, 240, 30);
    [btnTwo setTitle:@"vc2:v1" forState:UIControlStateNormal];
    btnImage = [UIImage imageNamed:@"image.png"];
    [btnTwo setImage:btnImage forState:UIControlStateNormal];
    [btnTwo addTarget:self action:@selector(goToOne) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnTwo];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a custom font to my wordpress website, but i'm not
I'm trying to put some custom list adapters into their own classes to make
Im trying to use Nets/HTTP to use POST and put in a custom user
I'm trying to put together a GUI for setting some pricing. There are three
hallo all i am trying to put a custom server control this time it
I've been trying to overload JMenu and put in some custom code to support
I finally managed to put together a custom callout UIView that gets shown when
I'm trying to put a custom ListView in a Dialog . My code is
I'm trying to put a checkbox in a salesforce page but the problem is
I have custom javascript code for tabs which works fine, but Im trying 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.