I want to create a button (not dynamically) bellow the last row in the table. All the rows and sections are fixed. Do I have to create another section and row just to add a button? and if yes how can I ajust the button to the same width and curvature of the cell?
Here is what I did. I create a specific section for the button and one row for it.
}else if(indexPath.section ==2)
{
UIButton *cellButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cellButton setFrame:CGRectMake(0.0f, 5.0f, cell.frame.size.width, 44.0f)]; // not filling the round parts of the cell
[cellButton setBackgroundColor: [UIColor yellowColor]];
[cellButton setTitle:#"test" forState:UIControlStateNormal];
[cell.contentView addSubview:cellButton];
}
return cell;
You don't. Set your button as the table footer view of your table view.
tableView.tableFooterView = myButton;
Related
i have button in tableviewcell.
what is diffrent between [cell addSubview:button] and [cell.contentview addsubview:button] ?
because when i use [cell addSubview:button] in tableview , button function work fine but my interface in table view messed up and button go to left cell after i scroll in views and back to tableview.
in other hand when i use [cell.contentview addsubview:button] button function not work and nothing save to myarray.
button code:
UIButton *button=(UIButton *) [cell viewWithTag:103];//fav
[button setImage:[UIImage imageNamed:#"unfav.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"fav.png"] forState:UIControlStateSelected];
button.frame = CGRectMake(0,0, 50, 50);
button.tag = indexPath.row;
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button]; // add the button to the cell
[cell bringSubviewToFront:button];
The contentView is the default view for the cell in which all the subviews are added.The cell.view is the main view in which contentView is itself added and cell.contentView covers the whole area of the cell.view. But in your case when you added the button to cell.view.
From apple docs about ContentView,
The content view of a UITableViewCell object is the default SuperView for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/#//apple_ref/occ/instp/UITableViewCell/contentView
I have a table view cell with a custom accessoryView, but it seems that the way it's laid out by default creates a 15-point margin on the right side. I want to get rid of it.
I can achieve the desired effect by overriding layoutSubviews, but that breaks edit mode animation (the accessory no longer slides in/out).
Any better way to do this?
Add subview instead of accessoryView
UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
deleteBtn.frame = CGRectMake(cell.contentView.frame.size.width-55, 2, 50, 50);
[deleteBtn setBackgroundImage:[UIImage imageNamed:#"trash.png"]
forState:UIControlStateNormal];
deleteBtn.backgroundColor = [UIColor clearColor];
//deleteBtn.alpha = 0.5;
deleteBtn.tag = indexPath.row;
[deleteBtn addTarget:self action:#selector(numberDeleteConfirm:)
forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:deleteBtn];
I have tableView with detailDisclosure button it works fine but i want to give title to detail disclosure button so i think i need to add custom UIButton for detailDisclosure is it possible to do like i want to do this without using custom cell.
If i want to give image it works fine but how may i give title to this button like comment.
cell.accessoryView = [[ UIImageView alloc ]
initWithImage:[UIImage imageNamed:#"loginN.png" ]];
Try this..
UIButton *btn = [[[UIButton alloc]init]autoerelease];
btn .frame = CGRectMake(210.0, 0.0, 90, 25);
btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:#"loginN.png"] forState:UIControlStateNormal];
[btn addTarget:self action:#selector(btnClickHandler:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubView: btn];
and in btnClickHandler do this to get indexPath
- (void)btnClickHandler :(UIButton *)button {
UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
//Get your data source object from indexPath.row.
}
Why don't u set the a button as accessory view just like u try setting an image..??
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, 80.0, 80.0);//Set the frame u need for the view
//Customize the button
[button setTitle:#"title" forState:UIControlStateNormal];
//And set it as accessory view
cell.accessoryView = button;
Here is the result...
How can I reference by code a button's tag value which I assigned earlier?
What I'm trying to do is create a list in a table view that has checkbox images in each row. I only want one to be selected at a time within each section, so once one is selected, I would loop through the other buttons to unselect the others.
Below is the code how I assign each button in cellForRowAtIndexPath:
UIButton *addCheckButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
addCheckButton.frame = CGRectMake(self.view.frame.size.width - 40.0f, 5.0f, 32.0f, 32.0f);
[addCheckButton setBackgroundImage:[UIImage imageNamed:#"checkbox_empty.png"]
forState:UIControlStateNormal];
[addCheckButton setBackgroundImage:[UIImage imageNamed:#"checkbox_full.png"]
forState:UIControlStateSelected];
[cell addSubview:addCheckButton];
[addCheckButton addTarget:self action:#selector(changeCheckState:) forControlEvents:UIControlEventTouchUpInside];
addCheckButton.tag = ([indexPath section] + 1) * 100 + [indexPath row];
I then can strip out the section and row of the selected button in my table view in the changeCheckState IBAction.
But I would also like something that I can say "Deselect buttons with tag 101, 102 and 103" within changeCheckState.
id my101Button = [view viewWithTag:101];
This question is one of those that are googled in seconds.
I've been looking for this for a while, but haven't found an answer (blame poor googling skills). I have a custom UITableViewCell class which, currently, consists of a custom UISwitch and a UILabel. I want to add a button that's only visible (And active) when the switch is set to "Yes". Right now I add the switch to the accessoryView, and leave it. However, the accessory view doesn't really have subviews, as far as I can tell, so here's my question:
Should I just create a UIView that has a button and a switch, size it to fit the cell's accessory view (or will it auto-size itself?), and put that in as the cell's accessory view? And is this typically the way that it's gone about?
Or is there a solution that I'm missing?
Thanks.
Here is an example:
UIButton* btdel = [[UIButton alloc] init];
btdel.tag = indexPath.row;
//[btdel setTitle:#"Delete Event" forState:UIControlStateNormal];
[btdel setBackgroundImage:[UIImage imageNamed:#"ButtonRemove.png"] forState:UIControlStateNormal];
[btdel addTarget:self action:#selector(deleteEvent:) forControlEvents:UIControlEventTouchUpInside];
// bt.titleLabel.frame = CGRectMake(0, 0, 95,24);
btdel.frame = CGRectMake(110, 0, 30,30);
[headerView addSubview:btdel];
[btdel release];
UIButton* bt = [[UIButton alloc] init];
bt.tag = indexPath.row;
[bt setTitle:#"Select a Dress" forState:UIControlStateNormal];
[bt setBackgroundImage:[UIImage imageNamed:#"findDress.png"] forState:UIControlStateNormal];
[bt addTarget:self action:#selector(showDresses:) forControlEvents:UIControlEventTouchUpInside];
bt.font=[UIFont systemFontOfSize:(CGFloat ) 13];
// bt.titleLabel.frame = CGRectMake(0, 0, 95,24);
bt.frame = CGRectMake(0, 3, 95,24);
[headerView addSubview:bt];
cell.accessoryView = headerView;