我正在尝试使用此代码调整UITableView
单元格的删除按钮的大小,但出于某种原因,x&你工作正常,但我无法改变高度和删除按钮的宽度。我在我的自定义UITableViewCell
课程中使用此代码,一切正常,优于宽度& “删除”按钮的高度。
我在这里失踪了什么?
- (void)layoutSubviews
{
[super layoutSubviews];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.0f];
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
CGRect newFrame = subview.frame;
newFrame.origin.x = 250;
newFrame.origin.y = 47;
newFrame.size.height = 30;
newFrame.size.width = 50;
deleteButtonView.frame = newFrame;
subview.frame = newFrame;
}
}
[UIView commitAnimations];}
答案 0 :(得分:3)
使用此代码...
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
UIView *deleteButtonView = (UIView *)[subview.subviews objectAtIndex:0];
CGRect f = deleteButtonView.frame;
f.origin.x = 250;
f.origin.y = 47;
f.size.width = 30;
f.size.height = 50;
CGRect sf = self.frame;
sf.size.width = 100;
sf.size.height = 100;
deleteButtonView.frame = f;
self.frame = sf;
}
请参阅此链接中的其他答案... iphone-uitableview-delete-button
答案 1 :(得分:2)
在自定义Cell类
中使用此代码-(void)layoutSubviews
{
NSMutableArray *subviews = [self.subviews mutableCopy];
UIView *subV = subviews[0];
[subviews removeObjectAtIndex:0];
CGRect f = subV.frame;
f.size.height = 70; // Here you set height of Delete button
subV.frame = f;
}
答案 2 :(得分:1)
在UITableviewCell中找到“UITableViewCellDeleteConfirmationView”以更改删除按钮的高度。
在自定义单元格类中使用此代码
- (void)layoutSubviews {
[super layoutSubviews];
NSMutableArray *subviews = [self.subviews mutableCopy];
while (subviews.count > 0)
{
UIView *subV = subviews[0];
[subviews removeObjectAtIndex:0];
if ([NSStringFromClass([subV class])isEqualToString:@"UITableViewCellDeleteConfirmationView"])//Here you select the subView of delete button {
UIView *deleteButtonView = (UIView *)[self.subviews objectAtIndex:0];
CGRect buttonFrame = deleteButtonView.frame;
buttonFrame.origin.x = deleteButtonView.frame.origin.x;
buttonFrame.origin.y = deleteButtonView.frame.origin.y;
buttonFrame.size.width = deleteButtonView.frame.size.width;
buttonFrame.size.height = 70; //Here you set the height
deleteButtonView.frame = buttonFrame;
}
}
}
答案 3 :(得分:0)
您也可以使用约束(适用于iOS 8.x +)来执行此操作。 这样动画(特别是删除按钮动画)保持整洁/没有UI故障。
在你的UITableViewCell子类中:
在您的班级匿名类别中声明弱属性:
gawk
禁用自动调整遮罩约束的转换并添加自己的约束:
awk
答案 4 :(得分:0)
<强> SWIFT 强>
覆盖CustomTableViewCell中的func layoutSubviews():UITableViewCell
override func layoutSubviews() {
for subview in self.subviews {
if String(describing: type(of: subview.self)).isEqualToString("UITableViewCellDeleteConfirmationView") {
var newFrame = subview.frame
newFrame.origin.y = 10
newFrame.size.height = 60
subview.frame = newFrame
}
}
}