[英]UITableViewCell with UITableViewCellAccessoryDisclosureIndicator remove right margin
編輯:添加了用於管理textLabel和detailTextLabel框架的代碼。
您可以通過在自定義單元格類中重寫layoutSubViews
方法來實現此目的(如果您不使用它,則首先創建一個,然后在表視圖中使用它)。 將以下代碼添加到表視圖單元類.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;
}
}
}
}
更改上面定義的常數以適合您的需求。
希望這可以幫助您解決問題。 謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.