Ios 有没有办法去掉截断标签中的省略号?

Ios 有没有办法去掉截断标签中的省略号?,ios,swift,uilabel,Ios,Swift,Uilabel,如果lineBreakingMode设置为ByTruncatingHead或ByTruncatingTail,是否有一种快速去除标签中省略号(…)的方法 我遇到了一种方法,并试图将其转换为swift,但无济于事(我失败得很惨)。 非常感谢任何帮助或提示 以下是我的转换: private func replaceElipses() { let origSize = self.frame let useWidth = origSize.size.width

如果
lineBreakingMode
设置为
ByTruncatingHead
ByTruncatingTail
,是否有一种快速去除标签中省略号(…)的方法

我遇到了一种方法,并试图将其转换为swift,但无济于事(我失败得很惨)。 非常感谢任何帮助或提示

以下是我的转换:

private func replaceElipses() {
        let origSize = self.frame
        let useWidth = origSize.size.width

        self.sizeToFit()

        let labelSize = (self.text! as NSString).sizeWithAttributes([NSFontAttributeName: self.font])

        if labelSize.width > useWidth {
            original = self.text!
            truncateWidth = useWidth
            systemfont = self.font
            subLength = (self.text?.characters.count)!

            var temp = ((self.text)! as NSString).substringToIndex(self.text!.characters.count-1) as NSString
            temp = temp.substringToIndex(self.getTruncatedStringPoint(subLength))
            temp = "\(temp)\("@")"

            var count = 0
            while (self.text! as NSString).sizeWithAttributes([NSFontAttributeName: self.font]).width > useWidth {
                count++
                temp = ((self.text)! as NSString).substringToIndex(self.text!.characters.count-(1+count)) as NSString
                temp = "\(temp)\("@")"
            }
            self.text = temp as String
            self.frame = origSize

        } else {
            self.frame = origSize
        }
    }

    func getTruncatedStringPoint(splitPoint: Int) -> Int {
        let splitLeft = original.substringToIndex(splitPoint) as NSString
        subLength /= 2

        if subLength <= 0 {
            return splitPoint
        } else if splitLeft.sizeWithAttributes([NSFontAttributeName: systemfont]).width > truncateWidth {
            return self.getTruncatedStringPoint(splitPoint - subLength)
        } else if splitLeft.sizeWithAttributes([NSFontAttributeName: systemfont]).width < truncateWidth {
            return self.getTruncatedStringPoint(splitPoint + subLength)
        } else {
            return splitPoint
        }
    }
private func replaceLises(){
让origSize=self.frame
让useWidth=origSize.size.width
self.sizeToFit()
让labelSize=(self.text!作为NSString)。SizeWithatAttributes([NSFontAttributeName:self.font])
如果labelSize.width>useWidth{
原文=self.text!
截断宽度=使用宽度
systemfont=self.font
子长度=(self.text?.characters.count)!
var temp=((self.text)!作为NSString)。substringToIndex(self.text!.characters.count-1)作为NSString
temp=子字符串到索引的温度(自GetRuncatedStringPoint(子长度))
temp=“\(temp)\(“@”)”
变量计数=0
while(self.text!as NSString).SizeWidthAttributes([NSFontAttributeName:self.font]).width>useWidth{
计数++
temp=((self.text)!作为NSString)。substringToIndex(self.text!.characters.count-(1+count))作为NSString
temp=“\(temp)\(“@”)”
}
self.text=temp作为字符串
self.frame=origSize
}否则{
self.frame=origSize
}
}
func getTruncatedStringPoint(拆分点:Int)->Int{
让splitLeft=original.substringToIndex(splitPoint)作为NSString
子长度/=2
如果子长度截断宽度{
返回self.getRuncatedStringPoint(拆分点-子长度)
}如果左拆分,则为else。SizeWithatAttributes([NSFontAttributeName:systemfont])。宽度<截断宽度{
返回self.getRuncatedStringPoint(拆分点+子长度)
}否则{
返回拆分点
}
}

显示您如何尝试转换代码,并解释您的转换错误。我逐行转换了代码,尽管做了一些修改(更新了我的答案以反映它),但什么也没有发生。是的,它被称为:(@Wain