将填充设置为UILabel裁剪字符

时间:2017-09-26 08:37:26

标签: ios xamarin.ios uilabel drawtextinrect

我正在向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增加高度,则仅在标签顶部添加填充。

带填充屏幕1 - 看起来不错,但缺少单词: enter image description here

没有通过屏幕2 - 显示整个消息: enter image description here

任何解决方案?

1 个答案:

答案 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
}