A plugin that extends the Nativescript Label with the functionality to adjust the font size according to the label's width.
npm install @nativescript/auto-fit-text
The following are examples of how to use the @nativescript/auto-fit-text
plugin in different JS flavors.
xmlns
attribute providing your prefix( AFT
, for example).<Page xmlns:AFT="@nativescript/auto-fit-text">
...
AutoFitText
view.<StackLayout class="p-20">
<AFT:AutoFitText text="Testinggggggggggggggggg" textWrap="false" />
</StackLayout>
The following is the complete code that results from the preceding steps:
<Page
xmlns="http://schemas.nativescript.org/tns.xsd"
loaded="pageLoaded"
class="page"
xmlns:AFT="@nativescript/auto-fit-text"
>
<StackLayout class="p-20">
<AFT:AutoFitText text="Testinggggggggggggggggg" textWrap="false" />
</StackLayout>
</Page>
import { NativeScriptAutoFitTextModule } from '@nativescript/auto-fit-text/angular';
@NgModule({
imports: [NativeScriptAutoFitTextModule],
})
<AutoFitText
row="2"
fontSize="48"
text="Lorem Ipsum this line of text with fontSize ignored because the text is so long."
textWrap="false"
/>
registerElement()
function to register the AutoFitText
view in the app.ts
file.import { registerElement } from 'nativescript-vue'
registerElement('AutoFitText', () => require('@nativescript/auto-fit-text').AutoFitText)
<AutoFitText
fontSize="48"
text="Lorem Ipsum this line of text with fontSize ignored because the text is so long."
/>
registerNativeViewElement()
function to register the AutoFitText
view in the app.ts
file.import { registerNativeViewElement } from 'svelte-native/dom'
registerNativeViewElement(
'autoFitText',
() => require('@nativescript/auto-fit-text').AutoFitText
)
<autoFitText fontSize="48" text="Lorem Ipsum this line of text with fontSize ignored because the text is so long." />
@grantland - android-autofittextview
Apache License Version 2.0, January 2004