【问题标题】:Remove dots in the end of attributedText xcode删除属性文本 xcode 末尾的点
【发布时间】:2018-05-21 12:48:26
【问题描述】:

Heloo.. 我是 ios、swift 和 xcode 的新手...

我在 swift 文件中有如下逻辑:

class ExpandableHeaderView: UITableViewHeaderFooterView {

    func customInit(menu: Menu, section: Int, delegate: ExpandableHeaderViewDelegate) {

        //Create Attachment

        let imageAttachment =  NSTextAttachment()

        var textAfterIcon: NSMutableAttributedString

        switch menu {

        case .HOME:

            imageAttachment.image = UIImage(named:"home")

            textAfterIcon = NSMutableAttributedString(string: " Home")

        :

        }

        //Set bound to reposition
        let imageOffsetY:CGFloat = -3.0;
        imageAttachment.bounds = CGRect(
            x: 0,
            y: imageOffsetY,
            width: imageAttachment.image!.size.width,
            height: imageAttachment.image!.size.height)
        //Create string with attachmen
        let attachmentString = NSAttributedString(attachment: imageAttachment)
        //Initialize mutable string
        let completeText = NSMutableAttributedString(string: "")
        //Add image to mutable string
        completeText.append(attachmentString)
        //Add your text to mutable string
        completeText.append(textAfterIcon)
        self.textLabel?.lineBreakMode = NSLineBreakMode.byTruncatingTail

        self.textLabel?.attributedText = completeText


        :
    }

}

但我得到的结果如下:

我已经添加了所有NSLineBreakMode.by*,但没有一个是完美的显示图像和标签:[image] Home

我怎样才能去掉textLabel?.attributedText最后的三个点?

真的让我很困惑……

所以,很高兴有人能帮助我...

环境:

  1. xCode v. 9.3

【问题讨论】:

  • 隐藏此self.textLabel?.lineBreakMode = NSLineBreakMode.byTruncatingTail 并检查\
  • 您的标签似乎太窄了。您是否为标签添加了任何宽度限制?
  • 尝试 textLabel.numberOfLines = 0
  • @chirag90 我尝试添加textLabel.numberOfLines = 0,但遇到了同样的问题
  • @Anbu.karthik 我禁用/评论了 self.textLabel?.lineBreakMode = NSLineBreakMode.bTruncatingTail` 仍然有同样的问题...

标签: ios swift xcode


【解决方案1】:

我不认为用“...”截断您的标签是个问题。您应该首先解决标签的正确大小问题。

【讨论】:

  • 你是如何添加标签的?它们是添加到 Storyboard 或 Xib 文件中吗?如果是这样,您应该通过使用 Interface Builder 将所需的约束添加到标签来解决大小问题。
  • @andlin 我添加的标签不在Storyboard 中,它在Swift 文件中..
  • 嗨 Rudi,试试这个教程:raywenderlich.com/160527/… | www.raywenderlich.com 总的来说有很多很好的教程,所以不要犹豫,从那里开始学习 ;-)
猜你喜欢
  • 2015-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多