Ios 带UINavigationController Swift的UITableView

Ios 带UINavigationController Swift的UITableView,ios,swift,xcode,Ios,Swift,Xcode,我试图复制这个设计 我很难把它设计得好看。我现在有这个 这是我的故事板 我使用uitableView和UITableViewCells创建了新功能。我的代码非常通用和简单: var settingsArray = ["My Account", "My Info", "test", "Sign Out"] func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

我试图复制这个设计

我很难把它设计得好看。我现在有这个

这是我的故事板

我使用uitableView和UITableViewCells创建了新功能。我的代码非常通用和简单:

 var settingsArray = ["My Account", "My Info", "test", "Sign Out"]
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return settingsArray.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "settingsCell")
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: "settingsCell")
        }
        cell?.textLabel!.text = settingsArray[indexPath.row]

        cell?.textLabel?.font = UIFont(name: "Avenir-Medium", size: 17.0)

        return cell!
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }
在复制第一个链接时,任何帮助都将不胜感激。谢谢

class CellName:UITableViewCell{
    let labelTitle:UILabel={
        let label = UILabel()
        label.numberOfLines = 0
        label.text = "loading"
        label.font = UIFont.systemFont(ofSize: 15)
        return label
    }()

    let arrowImage:UIImageView={
        let iv = UIImageView()
        iv.image = #imageLiteral(resourceName: "right_arrow")
        iv.clipsToBounds = true
        iv.contentMode = .scaleAspectFit
        return iv
    }()

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
       super.init(style: style, reuseIdentifier: reuseIdentifier)
       self.setUpCell()
    }

    func setUpCell() {
       selectionStyle = .blue
       addSubview(arrowImage)
       arrowImage.setHieghtOrWidth(height: 20, width: 20)
       arrowImage.centerOnYOrX(x: nil, y: true)
       arrowImage.rightAnchor.constraint(equalTo: rightAnchor, constant: -10).isActive = true 
       addSubview(labelTitle)
       labelTitle.anchors(left: rightAnchor, right: arrowImage.leftAnchor, top: topAnchor, bottom: bottomAnchor, leftConstant: 10, rightConstant: -10, topConstant: 0, bottomCosntant: 0) 
    }
}
在tableViewController中

var settingsArray = [
                      {
                       name : "My Account",
                       additionalText : nil
                      }
                      {
                       name : "My Info",
                       additionalText : nil
                      }
                      {
                       name : "Units",
                       additionalText :"Imperial(Pounds)" 
                      }
                    ]

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "settingsCell") as! CustomTableViewCell

    if let dictionary = settingsArray[indexPath.row] as? NSMutableDictionary {
      if let name = dictionary["name"] as? String {
         cell.nameLabel.text = name
      }
      if let addText = dictionary["additionalText"] as? String {
         cell.rightlabel.text = addText
         cell.rightlabel.addImageWith(name : "arrow-sign", behindText : true)
      }
    }


    cell.nameLabel.font = UIFont(name: "Avenir-Medium", size: 17.0)

    return cell
}


extension UILabel {

func addImageWith(name: String, behindText: Bool) {

    let attachment = NSTextAttachment()
    attachment.image = UIImage(named: name)
    let attachmentString = NSAttributedString(attachment: attachment)

    guard let text = self.text else {
        return
    }

    if (text.isEmpty) {
        return
    }

    if behindText {
        let labelText = NSMutableAttributedString(string: text + " ")
        labelText.append(attachmentString)
        self.attributedText = labelText
    } else {
        let labelText = NSAttributedString(string: " " + text)
        let mutableAttachmentString = NSMutableAttributedString(attributedString: attachmentString)
        mutableAttachmentString.append(labelText)
        self.attributedText = mutableAttachmentString
    }
}

func removeImage() {
    let text = self.text
    self.attributedText = nil
    self.text = text
}

}

您需要创建自定义单元格。您想要什么?(与第一个截图的设计相同?@Kuldeep是的,我正在尝试使第二个截图(我的代码)与第一个截图相同one@Etiekyed那么你面临的问题是什么?
var settingsArray = [
                      {
                       name : "My Account",
                       additionalText : nil
                      }
                      {
                       name : "My Info",
                       additionalText : nil
                      }
                      {
                       name : "Units",
                       additionalText :"Imperial(Pounds)" 
                      }
                    ]

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "settingsCell") as! CustomTableViewCell

    if let dictionary = settingsArray[indexPath.row] as? NSMutableDictionary {
      if let name = dictionary["name"] as? String {
         cell.nameLabel.text = name
      }
      if let addText = dictionary["additionalText"] as? String {
         cell.rightlabel.text = addText
         cell.rightlabel.addImageWith(name : "arrow-sign", behindText : true)
      }
    }


    cell.nameLabel.font = UIFont(name: "Avenir-Medium", size: 17.0)

    return cell
}


extension UILabel {

func addImageWith(name: String, behindText: Bool) {

    let attachment = NSTextAttachment()
    attachment.image = UIImage(named: name)
    let attachmentString = NSAttributedString(attachment: attachment)

    guard let text = self.text else {
        return
    }

    if (text.isEmpty) {
        return
    }

    if behindText {
        let labelText = NSMutableAttributedString(string: text + " ")
        labelText.append(attachmentString)
        self.attributedText = labelText
    } else {
        let labelText = NSAttributedString(string: " " + text)
        let mutableAttachmentString = NSMutableAttributedString(attributedString: attachmentString)
        mutableAttachmentString.append(labelText)
        self.attributedText = mutableAttachmentString
    }
}

func removeImage() {
    let text = self.text
    self.attributedText = nil
    self.text = text
}

}