Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.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-多行使用firstLineHeadIndent缩进_Ios_Xcode_Swift_Uiview_Uilabel - Fatal编程技术网

Ios UILabel-多行使用firstLineHeadIndent缩进

Ios UILabel-多行使用firstLineHeadIndent缩进,ios,xcode,swift,uiview,uilabel,Ios,Xcode,Swift,Uiview,Uilabel,我一直想缩进一段的第一行。 我一直在使用firstLineHeadIndent,如下所示: let comment_message_style = NSMutableParagraphStyle() comment_message_style.firstLineHeadIndent = 50.0 comment_message_style.headIndent = 0.0 // Tried to force other lines to 0 indent va

我一直想缩进一段的第一行。 我一直在使用firstLineHeadIndent,如下所示:

    let comment_message_style = NSMutableParagraphStyle()
    comment_message_style.firstLineHeadIndent = 50.0
    comment_message_style.headIndent = 0.0   // Tried to force other lines to 0 indent
    var comment_message_indent = NSMutableAttributedString(string: "HELLO\nTest1\nTest Long Line so that it will break without adding the new line char to the string.")        
    comment_message_indent.addAttribute(NSParagraphStyleAttributeName, value: comment_message_style, range: NSMakeRange(0, comment_message_indent.length))
    self.commentMessageLabel.attributedText = comment_message_indent
然而,每当我运行模拟器时,缩进将应用于所有新行。请参见下面的屏幕截图

我正在使用最新版本的Xcode 6.1,并在iOS 8.0上运行我的项目


有人知道吗?

问题是即使使用了,Xcode也无法识别第一行的结尾在哪里,我不知道为什么会这样

然而,另一种方法是替换

    var comment_message_indent = NSMutableAttributedString(string: "HELLO\nTest1\nTest Long Line so that it will break without adding the new line char to the string.")  

    var comment_message_indent = NSMutableAttributedString(string: "HELLO                        Test1\nTest Long Line so that it will break without adding the new line char to the string.")  
空格长度=第一行的字符总数-5


这应该可以完成工作,您的非第一行将正确缩进,您也不必添加头缩进

不幸的是,你的解决方案对我不起作用。我必须删除字符串两端的所有空白。这不完全是我想要的,但我同意。谢谢你抽出时间