ios - 如何强制按钮停留在 tableView 单元格的底部?

标签 ios tableview

我将一个按钮作为 subview 添加到我的 tableviewcells。工作正常。但我似乎无法弄清楚,如何强制它始终位于单元格的底部。 (如果你愿意的话,在分隔线的顶部)。单元格高度各不相同,因此固定位置并不明智。但我不知道如何添加动态位置。下面是添加按钮的代码:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
    action:@selector(buttonPressed:)
    forControlEvents:UIControlEventTouchDown];
    [button setTitle:@"+1" forState:UIControlStateNormal];
    button.frame = CGRectMake(0.0f, 70.0f, 160.0f, 15.0f);
    [cell addSubview:button];

最佳答案

添加按钮时设置自动调整大小掩码。我认为你想要的设置是:

button.autoresizingMask = UIViewAutoResizingFlexibleTopMargin;

在将按钮添加到单元格后执行此操作。

关于ios - 如何强制按钮停留在 tableView 单元格的底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10537381/

相关文章:

ios - 异步加载图片,奇怪的问题

ios - Swift 2.2 - SpriteKit - 子类 SKSpriteNode 类

ios - 获取 UITableView 错误 "unable to dequeue a cell with identifier cell"

iOS : Readjusting a UITableViewCell according the height of a UIImage in Swift

ios - 将界面生成器中的 tableView 连接到 NON-outlet 变量

iphone - 在 Xcode 中将仅 iPhone 应用程序编译到 iPad 设备

ios - Twitter completionHandler 在成功时卡住应用程序

ios - touchesEnded :withEvent: is not called

java - 将整数(非字符串)数据插入 JavaFX2 TableView

ios - 更新单个 TableView 单元格标签