Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UILabel中的numberOfLines在使用NSMutableAttributedString后未运行_Ios_Swift_String_Colors_Uilabel - Fatal编程技术网

Ios UILabel中的numberOfLines在使用NSMutableAttributedString后未运行

Ios UILabel中的numberOfLines在使用NSMutableAttributedString后未运行,ios,swift,string,colors,uilabel,Ios,Swift,String,Colors,Uilabel,我正在用UILabel制作多色文本。它工作得很好。但问题是,我可以在UIlabel中显示多行。这意味着numberOfLine属性无效 extension NSMutableAttributedString { func setColorForText(textForAttribute: String, withColor color: UIColor) { let range: NSRange = self.mutableString.range(of:

我正在用UILabel制作多色文本。它工作得很好。但问题是,我可以在UIlabel中显示多行。这意味着numberOfLine属性无效

     extension NSMutableAttributedString {

     func setColorForText(textForAttribute: String, withColor color: UIColor) {
        let range: NSRange = self.mutableString.range(of: textForAttribute, options: .caseInsensitive)
        self.addAttribute(NSAttributedString.Key.foregroundColor, value: color, range: range)

    }




         let stringValue = "Natural air is most important part of human body. people got too much problem because of it. please everybody try to do best part for it"


        let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: stringValue)
        attributedString.setColorForText(textForAttribute: "\(item.catName ?? "")", withColor: Colors.green)

        postInfoLabel.font = UIFont.systemFont(ofSize: ViewSize.width/33)
       postInfoLabel.numberOfLines = 0
           postInfoLabel.attributedText = attributedString

包装和截断标签文本的方法是根据您的用例将lineBreakMode属性值设置为NSLineBreakByWordWrapping或NSLineBreakByTruncingTail。当您将UILabel的numberOfLines属性设置为0时,这应该适用于您。

包装和截断标签文本的方法是根据您的用例将lineBreakMode属性值设置为NSLineBreakByWordWrapping或NSLineBreakByTruncingTail。当您将UILabel的numberOfLines属性设置为0时,这应该适用于您。

numberOfLines
不是一个函数,而是一个指示应显示多少行的属性。如果将此值设置为
0
,则说明label需要使用尽可能多的行来显示文本。您可以在中阅读更多详细信息


我不太确定通过将字体大小设置为
ViewSize.width/33
,您想要实现什么,可能存在问题(例如ViewSize计算不正确)。您能更详细地解释一下您想要实现什么,以及您得到了什么吗?

numberOfLines
不是一个函数,而是一个指示应显示多少行的属性。如果将此值设置为
0
,则说明label需要使用尽可能多的行来显示文本。您可以在中阅读更多详细信息


我不太确定通过将字体大小设置为
ViewSize.width/33
,您想要实现什么,可能存在问题(例如ViewSize计算不正确)。你能更详细地解释一下你想要实现什么,以及你得到了什么吗?

numberOfLines=0表示任意行数。所以你想在标签中显示多行文本,但只有一行?我使用了numberOfLines=0。应该显示为两行或三行的字符串。但它显示只有一行是正确的。你是对的朋友。Bazyl87检查您是否对标签应用了适当的约束?numberOfLines=0表示任意行数。因此,您希望将标签中的文本显示为多行,但只有一行?我使用了numberOfLines=0。应该显示为两行或三行的字符串。但它显示只有一行是正确的。你是对的朋友。BAZYL87检查是否对标签应用了适当的约束?ViewSize.width=self.view.frame.size.width但如果在
viewDidLoad
ViewSize.width=self.view.frame.size.width中使用,则无法设置图幅,但如果在
viewDidLoad