简体   繁体   English

删除按钮和线之间不需要的空间 swift xcode

[英]Remove the unwanted space between button and line swift xcode

I am new to iPhone application development.我是 iPhone 应用程序开发的新手。

在此处输入图像描述

I am designing the app like this.我正在设计这样的应用程序。 in this design, there are two buttons below to delete button and below to those two button, there is the line.在这个设计中,下面有两个按钮用于删除按钮,在这两个按钮的下方,有线条。 that you are seeing in this picture.你在这张照片中看到的。

What i want is, i want to add the line below to the delete button when those two buttons are hidden by some condition.我想要的是,当这两个按钮被某些条件隐藏时,我想将下面的行添加到删除按钮。 if those two buttons visible means, that line should come below to those two button.如果这两个按钮可见意味着,那条线应该在这两个按钮的下方。 Not below to the delete button.不在删除按钮下方。

I have added the following code in cellForRowAt function of TableView.我在 TableView 的 cellForRowAt function 中添加了以下代码。 it is not working.它不工作。

cell.line.frame = CGRect(x: 0, y:cell.btnDelete.frame.maxY, width: cell.line.frame.width , height: 1 ) 

Any body can help me to solve this issue.任何机构都可以帮助我解决这个问题。

I have added following code to.我添加了以下代码。

  func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
      return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {


    return UITableViewAutomaticDimension
}

and

    dataTable.rowHeight = UITableViewAutomaticDimension
    dataTable.estimatedRowHeight = 100

You have to achieve this using some tricky way.Use Stack View Add Show,Hide buttons to one UIView.add all other components to another UIView.Add UIStackView to your custom cell and add constraints like this.您必须使用一些棘手的方法来实现这一点。使用堆栈视图添加显示,将按钮隐藏到一个 UIView。将所有其他组件添加到另一个 UIView。将 UIStackView 添加到您的自定义单元格并添加这样的约束。

 NSLayoutConstraint.activate([
            stackView.leadingAnchor.constraint(equalTo: leadingAnchor),
            stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
            stackView.topAnchor.constraint(equalTo: topAnchor),
            stackView.bottomAnchor.constraint(equalTo: bottomAnchor),
 ])

set stackView distribution to.Fill.将 stackView 分布设置为.Fill。

when you want to show/hide buttons, you can add/remove the arranged subView from tableview cell stackView.If you are show/hide buttons in cellForItemAt make sure remove all arranged subviews before add.当您想要显示/隐藏按钮时,您可以从 tableview 单元格 stackView 添加/删除排列的子视图。如果您在cellForItemAt中显示/隐藏按钮,请确保在添加之前删除所有排列的子视图。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        cell.stackView.removeArrangedSubview(cell.viewOne)
        cell.stackView.removeArrangedSubview(cell.viewTwo)

        if isShowBuutons {
            cell.stackView.addArrangedSubview(cell.viewOne) //View with All other elements
            cell.stackView.addArrangedSubview(cell.viewTwo) //View with buttons
        }else{
            cell.stackView.addArrangedSubview(cell.viewOne) //View with All other elements
        }
    }

TableView 单元格结构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM