UITableViewCell for ipad中的UIButtons

时间:2011-05-07 07:06:56

标签: iphone objective-c ipad uitableview uibutton

我在UITableViewCell中创建了UIButtons。它在iphone中正常显示。但是当我为iPad升级这个应用程序时,UI按钮会转移到右侧并从桌面边界出来。这是我的代码

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;

2 个答案:

答案 0 :(得分:2)

您应该将按钮添加到单元格的contentView中,而不是直接添加到单元格中。

您可能还希望将按钮的框架原点相对于contentView的框架尺寸放置,+设置按钮的自动调整遮罩,以便根据单元格大小(可根据设备类型和/或界面方向更改)进行正确放置)。

答案 1 :(得分:0)

请尝试这个。在你的代码中删除[cell addSubview:button2];添加写入[cell.contentView addSubview:button2];并且还用于移除单元格的重叠或用于移除干扰按钮帧在分配所有单元格内容视图之前添加此for循环。

for(UIView * view in cell.contentView.subviews)

{

[view removeFromSuperview];

}

然后你可以在这里添加uibuttons uilabels等...

相关问题