0

我试图在 swift 3 的右上角添加属性文本,如图所示的 [PDF]

请检查屏幕截图

My requirement is... I have a picker view which has text values with list of countries..when a value is selected, I need to show that country name along with its Continent.

我可以显示标签中选择的选择器视图值,这很简单,但不确定如何在右上角附加大陆名称

如果我选择 USA,我的标签应显示 NA USA(其中 NA 是北美),其中 NA 代替 [PDF] 和 USA 代替附件中的“this is sample PDF”

我可以通过在标签前面添加 uiView 来显示它,但我的要求明确表示不要添加 uiview 来显示它。这应该是文本动态变化的 uilabel

不知道如何在此处使用属性字符串进行标记

请指导

4

1 回答 1

0

为此使用此代码

输出将是 27.67,其中 0.67 将显示小,27 将显示大

    let attString:NSMutableAttributedString = NSMutableAttributedString(string: "27.67", attributes: [NSFontAttributeName:Typography.largeDrawerSavingAmountLabel!])
    attString.setAttributes([NSFontAttributeName:Typography.smallDrawerSavingAmountLabel!,NSBaselineOffsetAttributeName:33], range: NSRange(location:attString.string.characters.count - 2,length:2))
    lblTotalAmount.attributedText = attString;

在哪里

你把你的字体放在Typography.largeDrawerSavingAmountLabelTypography.smallDrawerSavingAmountLabel

于 2017-04-24T05:12:39.633 回答