UITableView with UINavigationController Swift












-1















I'm trying to replicate this design



enter image description here
and I'm having trouble styling it to make it look good. I currently have this.



enter image description here



Here is my storyboard.



enter image description here



I new with UITableViews and UITableViewCells. My codes very generic and simple:



 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)
}


Any help will be much appreciated in replicating the first link. Thanks










share|improve this question

























  • You need to create your custom cell.

    – Nimesh
    Jan 1 at 6:37











  • what you want? (The same design as the first screenshot?)

    – Kuldeep
    Jan 1 at 9:57











  • @Kuldeep yes I am trying to make the second screenshot (my code) the same as the first one

    – Etiekyed
    Jan 1 at 22:38











  • @Etiekyed, Then what's the issues are you facing?

    – Kuldeep
    Jan 2 at 4:40
















-1















I'm trying to replicate this design



enter image description here
and I'm having trouble styling it to make it look good. I currently have this.



enter image description here



Here is my storyboard.



enter image description here



I new with UITableViews and UITableViewCells. My codes very generic and simple:



 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)
}


Any help will be much appreciated in replicating the first link. Thanks










share|improve this question

























  • You need to create your custom cell.

    – Nimesh
    Jan 1 at 6:37











  • what you want? (The same design as the first screenshot?)

    – Kuldeep
    Jan 1 at 9:57











  • @Kuldeep yes I am trying to make the second screenshot (my code) the same as the first one

    – Etiekyed
    Jan 1 at 22:38











  • @Etiekyed, Then what's the issues are you facing?

    – Kuldeep
    Jan 2 at 4:40














-1












-1








-1








I'm trying to replicate this design



enter image description here
and I'm having trouble styling it to make it look good. I currently have this.



enter image description here



Here is my storyboard.



enter image description here



I new with UITableViews and UITableViewCells. My codes very generic and simple:



 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)
}


Any help will be much appreciated in replicating the first link. Thanks










share|improve this question
















I'm trying to replicate this design



enter image description here
and I'm having trouble styling it to make it look good. I currently have this.



enter image description here



Here is my storyboard.



enter image description here



I new with UITableViews and UITableViewCells. My codes very generic and simple:



 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)
}


Any help will be much appreciated in replicating the first link. Thanks







ios swift xcode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 6:37









PinkeshGjr

2,16521731




2,16521731










asked Jan 1 at 6:28









EtiekyedEtiekyed

156




156













  • You need to create your custom cell.

    – Nimesh
    Jan 1 at 6:37











  • what you want? (The same design as the first screenshot?)

    – Kuldeep
    Jan 1 at 9:57











  • @Kuldeep yes I am trying to make the second screenshot (my code) the same as the first one

    – Etiekyed
    Jan 1 at 22:38











  • @Etiekyed, Then what's the issues are you facing?

    – Kuldeep
    Jan 2 at 4:40



















  • You need to create your custom cell.

    – Nimesh
    Jan 1 at 6:37











  • what you want? (The same design as the first screenshot?)

    – Kuldeep
    Jan 1 at 9:57











  • @Kuldeep yes I am trying to make the second screenshot (my code) the same as the first one

    – Etiekyed
    Jan 1 at 22:38











  • @Etiekyed, Then what's the issues are you facing?

    – Kuldeep
    Jan 2 at 4:40

















You need to create your custom cell.

– Nimesh
Jan 1 at 6:37





You need to create your custom cell.

– Nimesh
Jan 1 at 6:37













what you want? (The same design as the first screenshot?)

– Kuldeep
Jan 1 at 9:57





what you want? (The same design as the first screenshot?)

– Kuldeep
Jan 1 at 9:57













@Kuldeep yes I am trying to make the second screenshot (my code) the same as the first one

– Etiekyed
Jan 1 at 22:38





@Kuldeep yes I am trying to make the second screenshot (my code) the same as the first one

– Etiekyed
Jan 1 at 22:38













@Etiekyed, Then what's the issues are you facing?

– Kuldeep
Jan 2 at 4:40





@Etiekyed, Then what's the issues are you facing?

– Kuldeep
Jan 2 at 4:40












2 Answers
2






active

oldest

votes


















-1














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)
}
}





share|improve this answer
























  • I hope it work .

    – Nimesh
    Jan 1 at 6:49



















-1














import UIKit

class CustomTableViewCell : UITableViewCell {
@IBOutlet weak var nameLabel : UILabel
@IBoutlet weak var rightlabel : UILabel!
}


in 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
}

}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993467%2fuitableview-with-uinavigationcontroller-swift%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    -1














    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)
    }
    }





    share|improve this answer
























    • I hope it work .

      – Nimesh
      Jan 1 at 6:49
















    -1














    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)
    }
    }





    share|improve this answer
























    • I hope it work .

      – Nimesh
      Jan 1 at 6:49














    -1












    -1








    -1







    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)
    }
    }





    share|improve this answer













    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)
    }
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 1 at 6:45









    NimeshNimesh

    10311




    10311













    • I hope it work .

      – Nimesh
      Jan 1 at 6:49



















    • I hope it work .

      – Nimesh
      Jan 1 at 6:49

















    I hope it work .

    – Nimesh
    Jan 1 at 6:49





    I hope it work .

    – Nimesh
    Jan 1 at 6:49













    -1














    import UIKit

    class CustomTableViewCell : UITableViewCell {
    @IBOutlet weak var nameLabel : UILabel
    @IBoutlet weak var rightlabel : UILabel!
    }


    in 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
    }

    }





    share|improve this answer




























      -1














      import UIKit

      class CustomTableViewCell : UITableViewCell {
      @IBOutlet weak var nameLabel : UILabel
      @IBoutlet weak var rightlabel : UILabel!
      }


      in 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
      }

      }





      share|improve this answer


























        -1












        -1








        -1







        import UIKit

        class CustomTableViewCell : UITableViewCell {
        @IBOutlet weak var nameLabel : UILabel
        @IBoutlet weak var rightlabel : UILabel!
        }


        in 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
        }

        }





        share|improve this answer













        import UIKit

        class CustomTableViewCell : UITableViewCell {
        @IBOutlet weak var nameLabel : UILabel
        @IBoutlet weak var rightlabel : UILabel!
        }


        in 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
        }

        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 7:00









        Ankur LahiryAnkur Lahiry

        33239




        33239






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993467%2fuitableview-with-uinavigationcontroller-swift%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            Npm cannot find a required file even through it is in the searched directory

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith