带有 UITableViewCellAccessoryDisclosureIndicator 的 UITableViewCell 删除右边距
UITableViewCell with UITableViewCellAccessoryDisclosureIndicator remove right margin
我对 iOS 8 中引入的动态单元格高度使用自动布局 UITableViewCell
。
我设置了我的单元格并将 accessoryType
设置为 UITableViewCellAccessoryDisclosureIndicator
。我以编程方式进行所有布局。
我试过这样做:
self.layoutMargin = UIEdgeInsetsZero;
在 UITableViewCell
里面 init
方法
我想删除右边距或使用 contentView 调整大小设置自定义值
编辑:添加了用于管理 textLabel 和 detailTextLabel 框架的代码。
您可以通过覆盖自定义单元格 class 中的 layoutSubViews
方法来实现此目的(如果您没有使用,请先创建一个并在 table 视图中使用它).将以下代码添加到您的 table 视图单元格 class .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 8 中引入的动态单元格高度使用自动布局 UITableViewCell
。
我设置了我的单元格并将 accessoryType
设置为 UITableViewCellAccessoryDisclosureIndicator
。我以编程方式进行所有布局。
我试过这样做:
self.layoutMargin = UIEdgeInsetsZero;
在 UITableViewCell
里面 init
方法
我想删除右边距或使用 contentView 调整大小设置自定义值
编辑:添加了用于管理 textLabel 和 detailTextLabel 框架的代码。
您可以通过覆盖自定义单元格 class 中的 layoutSubViews
方法来实现此目的(如果您没有使用,请先创建一个并在 table 视图中使用它).将以下代码添加到您的 table 视图单元格 class .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;
}
}
}
}
更改上面定义的常量以满足您的需要。
希望这对您有所帮助并解决您的问题。谢谢