我正在向UILabel添加填充
import pandas as pd
from io import StringIO
from dfply import *
csv = StringIO("""id,name,value
1,abc,10
1,qwe,23
1,zxc,12
2,sdf,10
2,wed,23
2,abc,12
2,mnb,11""")
df = pd.read_csv(csv)
df['sequence'] = df.groupby('id').cumcount()
df = df[["id", "sequence", "name"]] >> spread(X.sequence, X.name)
df = df.set_index("id").fillna(0).rename(columns = lambda x: 'n{}'.format(x + 1)).reset_index()
print(df)
# id n1 n2 n3 n4
# 0 1 abc qwe zxc 0
# 1 2 sdf wed abc mnb
填充添加得很好,但最后一行被裁剪,因为我添加了额外的空白空间...如果我在此方法中用10增加高度,则仅在标签顶部添加填充。
任何解决方案?
答案 0 :(得分:0)
试试这个:
private var topInset: CGFloat = 5
private var bottomInset: CGFloat = 5
private var leftInset: CGFloat = 5
private var rightInset: CGFloat = 5
override func drawTextInRect(rect: CGRect) {
let insets = UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
super.drawTextInRect(UIEdgeInsetsInsetRect(rect, insets))
}
override public var intrinsicContentSize: CGSize {
var intrinsicSuperViewContentSize = super.intrinsicContentSize
intrinsicSuperViewContentSize.height += topInset + bottomInset
intrinsicSuperViewContentSize.width += leftInset + rightInset
return intrinsicSuperViewContentSize
}