Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create an info button programmatically at the top right corner?

I'm trying to do this but the button don't show:

// Create a Button to get Help          
UIButton *helpButton =  [UIButton buttonWithType:UIButtonTypeInfoDark ] ;
CGRect buttonRect = helpButton.frame;

// Calculate the top right corner
buttonRect.origin.x = self.tableView.frame.size.width - buttonRect.size.width - 8;
buttonRect.origin.y = self.tableView.frame.size.height - buttonRect.size.height - 8; 
[helpButton setFrame:buttonRect];

[helpButton addTarget:self action:@selector(doHelp:)
forControlEvents:UIControlEventTouchUpInside];
[helpButton setEnabled:TRUE];
[self.tableView addSubview:helpButton];

what am I doing wrong?

UPDATE the fix code is here for anyone that is interested:

// Create a Button to get Help          
UIButton *helpButton =  [UIButton buttonWithType:UIButtonTypeInfoDark ] ;
CGRect buttonRect = helpButton.frame;

// CALCulate the bottom right corner
buttonRect.origin.x = self.view.frame.size.width - buttonRect.size.width - 8;
buttonRect.origin.y = buttonRect.size.height - 8; 
[helpButton setFrame:buttonRect];

[helpButton addTarget:self action:@selector(doHelp:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:helpButton];
like image 755
Tomer Even Avatar asked Aug 31 '11 18:08

Tomer Even


People also ask

How do I make a button clickable in Swift?

Select Touch Up Inside in the event drop-down list. In the Arguments drop-down list, you can select Sender or Sender And Event. Click Connect button, there will add a method in the ViewController source code.


1 Answers

try to add it to self.view not self.tableview

like image 148
TommyG Avatar answered Oct 31 '22 08:10

TommyG