简体   繁体   中英

SuperScript in LaunchScreen.storyboard (AttributedString in Xamarin.Forms for iOS)

I need to add a trademark superscript to my launchscreen, so I've added 2 fragments to a TextView in xml as follows:

<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="center" id="258" translatesAutoresizingMaskIntoConstraints="NO" fixedFrame="YES" usesAttributedText="YES" selectable="NO" editable="NO">
    <rect key="frame" x="20" y="460" width="374" height="128"/>
    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinX="YES" flexibleMaxY="YES"/>
    <color key="backgroundColor" colorSpace="calibratedWhite" white="0" alpha="0"/>
    <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
    <attributedString key="attributedText">
        <fragment content="TrademarkedName ">
            <attributes>
                <color key="NSColor" colorSpace="calibratedRGB" red="1" green="1" blue="1" alpha="1"/>
                <font key="NSFont" name="HelveticaNeue" family="Helvetica Neue" size="20"/>
                <paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
            </attributes>
        </fragment>
        <fragment content="TM">
            <attributes>
                <color key="NSColor" colorSpace="calibratedRGB" red="1" green="1" blue="1" alpha="1"/>
                <font key="NSFont" name="HelveticaNeue" family="Helvetica Neue" size="12"/>
                <paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
            </attributes>
        </fragment>
    </attributedString>
</textView>

However, the "TM" is getting aligned to the bottom baseline of the text.

在此处输入图片说明

How do I, in XML, superscript this "TM" text fragment to vertically-align it to the top and\\or set it's baseline to vertical top?

Tested on XCode, no Xamarin.

You need to add this: <integer key="NSSuperScript" value="1"/> .

<fragment content="TM">
    <attributes>
        <color key="NSColor" colorSpace="calibratedRGB" red="1" green="1" blue="1" alpha="1"/>
        <font key="NSFont" name="HelveticaNeue" family="Helvetica Neue" size="12"/>
        <paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
        <integer key="NSSuperScript" value="1"/>
    </attributes>
</fragment>

How did I get it?
Modifying attributedText in Interface Builder is not easy, it's hard (not really friendly user on that one).
So what I do in these case it to open TextEdit.app, do what I want and copy/paste it into the attributedText box.
Then I just open the Interface Builder file as Source code, find it and gave you the line.

I guess you can play with the value of 1, I'll let you try it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM