我创建了一个带有文本字段的自定义 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
在 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
}
}
但是文本框在图片下面
我尝试在我的自定义单元格中插入 imageView
但是第一条分隔线的宽度不同
我该如何解决这个问题? 谢谢!
最佳答案
分隔线具有两种不同宽度的原因是,当您最初将 imageView 放在自定义单元格之外时,它位于图像的顶部并覆盖了分隔线。当您将 imageview 放在分隔符内时,它是可见的。看起来图像具有白色背景,因此它们掩盖了分隔线。如果我的猜测是正确的,请检查您的图标背景。如果它是白色的,请将它们更改为透明的。否则在 ImageView 和单元格底部之间提供一些填充
关于ios - UITableViewCell 中的 UITextField 使用单元格的 imageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45173831/