UIButtons in UITableViewCell for ipad

I created UIButtons in a UITableViewCell. It displays correctly on iphone. But when I update this app for iPad, UIbuttons shifts to the right and leaves the table border. Here is my code

UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
[button2 setFrame:CGRectMake(47.0f, 100.0f, 16, 16.0f)];

[button2 setImage:[UIImage imageNamed:@"Delete.png"] forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button2];



return cell;
+3
source share
2 answers

You should probably add a button to the contentView cell, not directly to the cell.

You may also want to place the beginning of the button frame relative to the size of the contentView frame, + set the button auto-mask to fit correctly according to the size of the cell (which may vary depending on the type of device and / or interface orientation).

+2
source

, . remove [cell addSubview: button2]; [cell.contentView addSubview: button2]; , .

( UIView * cell.contentView.subviews)

{

[view removeFromSuperview];

}

uibuttons uilabels ..

0

All Articles