ios - UITableViewCell 中的 UITextField 使用单元格的 imageView

标签 ios swift uitableview uiimageview uitextfield

我创建了一个带有文本字段的自定义 UITableViewCell,但我想使用单元格的 ImageView ,而不是在我的自定义单元格中插入一个。

这是我的代码:

import UIKit

class TextFieldTableViewCell: UITableViewCell, UITextFieldDelegate {

    @IBOutlet weak var textField : UITextField!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

这是xib

xib

在 View Controller 中:

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

        if indexPath.row == 0 {
            let cell : TextFieldTableViewCell! = tableView.dequeueReusableCell(withIdentifier: "textFieldCell", for: indexPath) as! TextFieldTableViewCell

            cell!.textField.text = "William Stevenson"
            cell!.textField.tag = indexPath.row
            cell!.imageView?.image = UIImage.init(icon: .FAUser, size: CGSize(width: 35, height: 35), textColor : UIColor.gray)

            return cell
        }
}

但是文本框在图片下面

first

我尝试在我的自定义单元格中插入 imageView

xib 2

但是第一条分隔线的宽度不同

enter image description here

我该如何解决这个问题? 谢谢!

最佳答案

分隔线具有两种不同宽度的原因是,当您最初将 imageView 放在自定义单元格之外时,它位于图像的顶部并覆盖了分隔线。当您将 imageview 放在分隔符内时,它是可见的。看起来图像具有白色背景,因此它们掩盖了分隔线。如果我的猜测是正确的,请检查您的图标背景。如果它是白色的,请将它们更改为透明的。否则在 ImageView 和单元格底部之间提供一些填充

关于ios - UITableViewCell 中的 UITextField 使用单元格的 imageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45173831/

相关文章:

ios - NumberFormatter 未对 "fr_CH"区域设置使用正确的小数分隔符

iphone - 在 tableviewcell 中设置文本标签的位置?

ios - 在 iOS 的 UITableView 中展开/折叠部分

ios - 更改 if 语句的 Swift 约束

ios - 如何使用 NSUserDefaults 动态分配空间?

ios - Swift:比较字典键

ios - 在 XCode 上为 Playground 设置 "Value History"和 "Quick Look"的默认文本颜色

ios - 获取以编程方式创建的 subview 的框架

swift - 自动续订订阅 buy_date 和 expires_date 相等

ios - iOS 9 阻止与以编程方式创建的 UISearchController 进行交互