- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用自动布局UITableViewCell
来实现iOS 8中引入的动态单元格高度。我设置了单元格并将 accessoryType
设置为 UITableViewCellAccessoryDisclosureIndicator
。我以编程方式进行所有布局。
我尝试这样做:self.layoutMargin = UIEdgeInsetsZero;
在 UITableViewCell
内的 init
方法
我想删除右边距或通过 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/
场景:使用自定义单元 UITableViewCell XIB(没有任何 Storyboard )。 另外:在 NIB 中设置访问器类型。 - 我在NIB和通过代码都试过了。 尝试设置单元访问器类型:
我想在我的应用程序的不同部分使用普通人字形。有谁知道图像的名称,所以我可以调用 [UIImage imageNamed:@"AccessoryDisclosureIndicator.png"] ? 最
我正在为 iOS 应用制作一个带有可展开/可折叠单元格的 UITableView。我在这些单元格上放置了一个 UITableViewCellAccessoryDisclosureIndicator,但
下图中的“Office”这个标签叫什么? 如何以编程方式设置它? 最佳答案 这似乎是具有 UITableViewCellStyleValue1 样式的表格单元格的 detailTextView。 您可
我正在尝试制作一个自定义的 UITableViewCellAccessoryDisclosureIndicator,它比普通指示器大一点,并且颜色不同。我想知道是否有人可以告诉我如何访问指标和高亮指标
一个简单的问题,我想将 UITableViewCellAccessoryDisclosureIndicator(tableView 右侧的箭头)的颜色从默认的灰色更改为白色。 cell.accesso
我使用自动布局UITableViewCell来实现iOS 8中引入的动态单元格高度。我设置了单元格并将 accessoryType 设置为 UITableViewCellAccessoryDisclo
我在一个 UIViewController(不是 UITableViewController)的 TableView 中有两个表。现在我只想让其中一个单元格添加 UITableViewCellAcce
我创建了一个方法 - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSInde
我是一名优秀的程序员,十分优秀!