gpt4 book ai didi

ios - 带有 UITableViewCellAccessoryDisclosureIndicator 的 UITableViewCell 删除右边距

转载 作者:行者123 更新时间:2023-11-29 01:46:37 25 4
gpt4 key购买 nike

我使用自动布局UITableViewCell来实现iOS 8中引入的动态单元格高度。我设置了单元格并将 accessoryType 设置为 UITableViewCellAccessoryDisclosureIndicator。我以编程方式进行所有布局。

我尝试这样做:self.layoutMargin = UIEdgeInsetsZero;UITableViewCell 内的 init 方法

enter image description here

我想删除右边距或通过 contentView 调整大小设置自定义值

最佳答案

编辑:添加了用于管理 textLabel 和 detailTextLabel 框架的代码。

您可以通过覆盖自定义单元格类中的 layoutSubViews 方法来实现这一点(如果您不使用一个,则先创建一个并在您的 TableView 中使用它)。将以下代码添加到您的 TableView 单元格类 .m 文件中:

const int ACCESORY_MARGIN = -10;
const int LABEL_MARGIN = -10;

- (void)layoutSubviews {
[super layoutSubviews];

CGRect frame;
frame = self.textLabel.frame;
frame.origin.x += LABEL_MARGIN;
frame.size.width -= 2 * LABEL_MARGIN;
self.textLabel.frame = frame;

frame = self.detailTextLabel.frame;
frame.origin.x += LABEL_MARGIN;
frame.size.width -= 2 * LABEL_MARGIN;
self.detailTextLabel.frame = frame;

if (self.accessoryType != UITableViewCellAccessoryNone)
{
float estimatedAccesoryX = MAX(self.textLabel.frame.origin.x + self.textLabel.frame.size.width, self.detailTextLabel.frame.origin.x + self.detailTextLabel.frame.size.width);

for (UIView *subview in self.subviews) {
if (subview != self.textLabel &&
subview != self.detailTextLabel &&
subview != self.backgroundView &&
subview != self.contentView &&
subview != self.selectedBackgroundView &&
subview != self.imageView &&
subview.frame.origin.x > estimatedAccesoryX) {
frame = subview.frame;
frame.origin.x -= ACCESORY_MARGIN;
subview.frame = frame;
break;
}
}
}
}

更改上面定义的常量以满足您的需要。

希望这有助于解决您的问题。谢谢。

关于ios - 带有 UITableViewCellAccessoryDisclosureIndicator 的 UITableViewCell 删除右边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31850852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com