Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.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 使用Swift向UILabel添加顶部和底部填充_Ios_Swift_Uilabel_Nsattributedstring - Fatal编程技术网

Ios 使用Swift向UILabel添加顶部和底部填充

Ios 使用Swift向UILabel添加顶部和底部填充,ios,swift,uilabel,nsattributedstring,Ios,Swift,Uilabel,Nsattributedstring,如何在UILabel中的内容顶部和底部添加填充 我试图通过NSAttributedString文本找到这样做的方法,但似乎找不到只在顶部和底部应用边距的方法。在swift中执行此操作:- class Label: UILabel { override func drawTextInRect(rect: CGRect) { super.drawTextInRect(UIEdgeInsetsInsetRect(rect, UIEdgeInsets(top: 0, left:

如何在
UILabel
中的内容顶部和底部添加填充

我试图通过
NSAttributedString
文本找到这样做的方法,但似乎找不到只在顶部和底部应用边距的方法。

在swift中执行此操作:-

class Label: UILabel {
    override func drawTextInRect(rect: CGRect) {
        super.drawTextInRect(UIEdgeInsetsInsetRect(rect, UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)))
    }
}

为什么不在标签和相邻标签之间添加一些空间?应该提到,但它嵌入在tableview单元格中。单元格是否使用自动布局(和自调整大小)?是的,但内容是通过编程添加的,并且随着文本量的不同而变化,有些是多行的,因此出现在单元格的任何边缘。你有一个可视化的例子吗?如何实现它?你可以通过故事板直接使用它作为自定义类。