In my NativeScript project, I'm trying to make a bottom bar with an icon and then the word that resembles it underneath it. Like this
Here's the html of what I tried to do:
<GridLayout rows="*,60">
<ScrollView row="0">
<WrapLayout orientation="horizontal">
<Label text="There are no leagues currently." style="color: black; text-align: center; font-weight: bold"></Label>
<Label text="Contact your commissioner" style="color: black; text-align: center; font-weight: bold"></Label>
<Label text="to create one." style="color: black; text-align: center; font-weight: bold"></Label>
</WrapLayout>
</ScrollView>
<StackLayout row="1" orientation="horizontal">
<Button textWrap="true" width="25%">
<FormattedString>
<Span text="\n" class="fa"></Span>
<Span text="Home"></Span>
</FormattedString>
</Button>
<Button textWrap="true" width="25%">
<FormattedString>
<Span text="\n" class="fa"></Span>
<Span text="All Cocktails"></Span>
</FormattedString>
</Button>
<Button textWrap="true" width="25%">
<FormattedString>
<Span text="\n" class="fa"></Span>
<Span text="Favorite"></Span>
</FormattedString>
</Button>
<Button textWrap="true" width="25%">
<FormattedString>
<Span text="\n" class="fa"></Span>
<Span text="Profile"></Span>
</FormattedString>
</Button>
</StackLayout>
</GridLayout>
and here's my css:
.fa {
font-family: 'Font Awesome 5 Free';
}
However, whenever I try to do this, it comes out like this
I'm not quite sure where to go so any help would be great. Thanks!
Here's a working example of my code: https://play.nativescript.org/?template=play-ng&id=r8Jodt&v=19
Use the GridLayout for BottomBar, you can look for the playground sample here
<GridLayout columns="*,*,*,*" rows="*,*" width="100%" row="1" backgroundColor="lightgray">
<Label text="" row="0" col="0" class="fa" width="100%" textAlignment="center"></Label>
<Label text="Home" row="1" col="0" width="100%" textAlignment="center"></Label>
<Label text="" row="0" col="1" class="fa" width="100%" textAlignment="center"></Label>
<Label text="All Cocktails" row="1" col="1" width="100%" textAlignment="center"></Label>
<Label text="" row="0" col="2" class="fa" width="100%" textAlignment="center"></Label>
<Label text="Favorite" row="1" col="2" width="100%" textAlignment="center"></Label>
<Label text="" row="0" col="3" class="fa" width="100%" textAlignment="center"></Label>
<Label text="Profile" row="1" col="3" width="100%" textAlignment="center"></Label>
</GridLayout>
The actual problem here is that \n works only with JavaScript, while using it in HTML (XML) file you should use the encode version of the character that is
, that should give you a new line.
Are you trying to have a custom TabBar for your TabView? If Yes, you may try the nativescript-vector-icons which allows you to use font icons on TabBar.
Make their position as display:absolute and within the class it should be inline-block. With some margins it should be easy to adjust
I would contain all the buttons in a div, and then each button and label group in it's own div.
<div id='button-row'>
<div class='bottom-button>
<button></button>
<p class='label>Label</p>
</div>
<div class='bottom-button>
<button></button>
<p class='label>Label</p>
</div>
// repeat for your buttons
</div>
Your css:
.button-row {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.bottom-button {
display: flex;
flex-direction: column;
justify-content: center;
// the font awesome icons are considered text I believe, so
text-align: center;
// would also work
}
This will make all your buttons in the row evenly spaced, and place your button on top of the label. I like using flexbox because its quick and easy, and mobile responsive. I'm not a CSS pro by any means but it works for me.
Edit: just saw your markup. Try giving formatted string the css of .bottom-button and see if that works.
For \n just worked for android.
using hex code
also not worked for both ios and android.
the final solution I find is as below:
(for nativescript-vue)
<Label textWrap="true" col="0" row="0">
<FormattedString>
<Span class="number" :text="days" />
<Span class="format" :text="'\n' + 'Gün'" />
</FormattedString>
</Label>
Related
Tell us about the problem
I am trying to horizontally set the content that is grouped with the function of but is not possible, because all content is horizontal.
Which platform(s) does your issue occur on?
Both
Please tell us how to recreate the issue in as much detail as possible.
<RadListView
[items]="dataItems"
#productsListView
[groupingFunction]="grouping"
>
<ng-template tkListItemTemplate let-item="item">
<StackLayout orientation="horizontal" width="100%">
<MDCardView width="100" height="100">
<Image stretch="aspectFill" [src]="item.image"></Image>
</MDCardView>
</StackLayout>
</ng-template>
<ng-template tkGroupTemplate let-category="category">
<GridLayout columns="*, auto" ios:height="50">
<Label
col="0"
style="font-weight: bold; font-size: 24"
[text]="category"
></Label>
<Label
col="1"
style="font-size: 12; color: gray;"
text="Ver más"
></Label>
</GridLayout>
</ng-template>
<ListViewGridLayout
tkListViewLayout
itemHeight="100"
scrollDirection="Horizontal"
></ListViewGridLayout>
</RadListView>
Try ScrollView within tkGroupTemplate
<ng-template tkGroupTemplate let-category="category">
<GridLayout>
<ScrollView orientation="horizontal" scrollBarIndicatorVisible="false">
<Label class="m-5 h2" [text]="category"></Label>
</ScrollView>
</GridLayout>
</ng-template>
Playground Sample
I am trying to display a background image on my login page, it is not showing.
I have tried adding the class to the page and my layout. Neither is working.
Is there something in my code that is preventing this for some reason?
<Page loaded="pageLoaded" class="page bgImage" actionBarHidden="true" xmlns="http://www.nativescript.org/tns.xsd">
<FlexboxLayout class="page">
<GridLayout rows="auto, auto, auto">
<StackLayout class="form ">
<Image class="logo" src="~/images/johnevolve.png" />
<Label class="header" text="Health Conscious" />
<StackLayout class="input-field">
<Label text="Username" />
<TextField class="input" text="{{ email }}" hint="Email"
keyboardType="email" autocorrect="false"
autocapitalizationType="none" returnKeyType="next" />
<Label class="hr-light" />
</StackLayout>
<StackLayout class="input-field">
<Label text="Password" />
<TextField id="password" class="input" text="{{ password }}"
hint="Password" secure="true" returnKeyType="{{ isLoggingIn ? 'done' : 'next' }}" />
<Label class="hr-light" />
</StackLayout>
<StackLayout class="input-field" visibility="{{ !isLoggingIn ? 'visible' : 'collapse' }}">
<TextField id="confirmPassword" class="input" text="{{ confirmPassword }}"
hint="Confirm password" secure="true" returnKeyType="done" />
<Label class="hr-light" />
</StackLayout>
<Button text="{{ isLoggingIn ? 'Log In' : 'Sign Up' }}" tap="{{ submit }}"
class="btn btn-primary m-t-20" />
<Label visibility="{{ isLoggingIn ? 'visible' : 'collapse' }}"
text="Forgot your password?" class="login-label" tap="{{ forgotPassword }}" />
</StackLayout>
</GridLayout>
<Label class="login-label sign-up-label" tap="{{ toggleForm }}">
<FormattedString>
<Span text="{{ isLoggingIn ? 'Don’t have an account? ' : 'Back to Login' }}" />
<Span text="{{ isLoggingIn ? 'Sign up' : '' }}" class="bold" />
</FormattedString>
</Label>
</FlexboxLayout>
</Page>
and my css:
.bgImage {
background-image: url("~/images/1-login.png");
}
Edit: Here is the page css rule in case you need that:
.page {
align-items: center;
flex-direction: column;
}
Does anyone know what's going wrong here?
Thank you.
Image In Question:
If this is NativeScript 5.x and you are using HMR/Webpack; the issue is most likely WebPack caused. I have a blog article about this on how to disable HMR mode and re-use Legacy mode.
In a nutshell you need to re-enable Legacy mode.
http://fluentreports.com/blog/?p=935
Please note; this is only relevent to NativeScript 5.x; NativeScript 6 (coming out shortly) will probably not let you re-enable legacy mode.
If you find legacy mode does actually fix your issue; please report this issue to the https://github.com/nativescript/NativeScript-Dev-Webpack repo so it can be looked at.
There was the problem with your FlexboxLayout . It was taking the 100% height and overlapping the background image with it's content.
You can also try with giving background Image to your FlexboxLayout.
<FlexboxLayout class="page bgImage">
and in app.css
.bgImage{
/* background-color: green; */
background-image: url("~/images/1-login.png");
background-repeat: no-repeat;
background-size: cover
}
I have created a playground for you here.
I need something like this:
But this is what I have at the moment:
.rotate {
transform: rotate(-90deg);
font-size: 16px;
color: #FFFFFF;
}
This is my code:
<StackLayout backgroundColor="#3C414B" width="12%" height="100%" horizontalAlignment="center" verticalAlignment="center" (tap)="openDrawer('Right')">
<StackLayout class="rotate" orientation="horizontal">
<Label class="fa" style="margin-right: 10px" text=""></Label>
<Label width="100%" class="" text="New Category" textwrap="false"></Label>
</StackLayout>
</StackLayout>
You will have to set the height explicitly to the width of the element, transform doesn't take care of that by default.
Or you may even consider using an image, here is a related thread from Forums.
It looks like you rotate inner <StackLayout class="rotate" ...>, but it still get width limit of outer <StackLayout width="12%" ...>
Try so:
<StackLayout class="rotate" backgroundColor="#3C414B" width="100%" height="12%" horizontalAlignment="center" verticalAlignment="center">
<StackLayout orientation="horizontal">
<Label class="fa" style="margin-right: 10px" text=""></Label>
<Label text="New Category" textwrap="false" backgroundColor="yellow"></Label>
</StackLayout>
</StackLayout>
Or try to find solution with other layout type. For example, AbsoluteLayout
I need to create an Image button which includes a custom image and a label in {N} + Angular.
Something like this:
Here's my code. I'm using the stack layout inside the grid layout. I can't see the label below the image.
<GridLayout columns="*,*" rows="*,*,*,*,*,*" width="400" height="400">
<StackLayout class=" btn-sq-lg " col="0" row="0" (tap)="gotoSRTPage()">
<Image col="0" row ="1" src="res://ic_briefcase" > </Image>
<Label class= "label" textWrap="true" col="0" row="2" text="SRT" horizontalAlignment="center" verticalAlignment="center"></Label>
</StackLayout>
<StackLayout class=" btn-sq-lg " col="1" row="0" (tap)="">
<Image col="1" row ="1" src="res://ic_blog" > </Image>
<Label class= "label" col="1" row="2" text="SRT" horizontalAlignment="center" verticalAlignment="center"</Label>
</StackLayout>
<StackLayout class=" btn-sq-lg " col="0" row="3" (tap)="">
<Image col="0" row ="4" src="res://ic_reminder" > </Image>
<Label class= "label" textWrap="true" col="0" row="5" text="SRT" horizontalAlignment="center" verticalAlignment="center"></Label>
</StackLayout>
<StackLayout class=" btn-sq-lg " col="1" row="3" (tap)="">
<Image col="1" row ="4" src="res://ic_announcement" > </Image>
<Label class="label" textWrap="true" col="1" row="5" text="SRT" horizontalAlignment="center" verticalAlignment="center"></Label>
</StackLayout>
</GridLayout>
css file:
.btn-sq-lg {
background-color: white;
}
.label {
text-align: center;
color:#00caab;
}
So far i haven't found a straight-forward way to do it but i have a work around
You can try the following
some.component.html
<StackLayout class="btn-img" orientation="horizontal" padding="5" (tap)="onTappedFun()" >
<Image src="res://facebook" width="10%" height="100%" marginRight="10"></Image>
<Label text="Login via Facebook" verticalAlignment="center"></Label>
</StackLayout>
some.component.css
.btn-img{
border-radius: 5;
border-width: 1;
color: white;
margin: 10;
font-size: 22;
border-color: #2b3c6a;
background-color: #3B5997;
}
some.component.ts
onTappedFun(){
console.log("Hey i was tapped");
}
Result
Using only CSS you can reach the desired style:
.my-button {
color: #395469;
background-color: #FFFFFF;
background-image: url("https://play.nativescript.org/dist/assets/img/NativeScript_logo.png");
background-repeat: no-repeat;
background-position: 35 28;
background-size: 60 60;
border-width: 2;
border-color: #395469;
border-radius: 28;
height: 56;
font-size: 16;
}
In the XML apply the style class:
<Button text="I like NativeScript" class="my-button"></Button>
You can try this :
<GridLayout columns="*,*" rows="*,*" width="400" height="400">
<StackLayout row="0" col="0" orientation="vertical">
<Image src="~/images/star-empty.png" height="80%"></Image>
<Label class="label" textWrap="true" text="Button Name1" height="20%"></Label>
</StackLayout>
<StackLayout row="0" col="1" orientation="vertical">
<Image src="~/images/star-empty.png" height="80%"></Image>
<Label class="label" textWrap="true" text="Button Name2" height="20%"></Label>
</StackLayout>
<StackLayout row="1" col="0" orientation="vertical">
<Image src="~/images/star-empty.png" height="80%"></Image>
<Label class="label" textWrap="true" text="Button Name3" height="20%"></Label>
</StackLayout>
<StackLayout row="1" col="1" orientation="vertical">
<Image src="~/images/star-empty.png" height="80%"></Image>
<Label class="label" textWrap="true" text="Button Name4" height="20%"></Label>
</StackLayout>
</GridLayout>
<Button>
<Image res="<path>"></Image>
<Label text="{{text}}"></Label>
</Button>
--EDIT--
Why have I been downvoted for this? It answers the question that was asked?
Using this Layout:
<GridLayout columns="70, *" rows="auto, auto, auto">
<Label row="0" col="0" rowSpan="3" text="A" style="background-color: red;"></Label>
<Label row="0" col="1" text="B" style="background-color: green;"></Label>
<Label row="1" col="1" text="C" visibility="collapse" style="background-color: blue;"></Label>
<Label row="2" col="1" text="D" style="background-color: orange"></Label>
</GridLayout>
Is there a reason I can see a white space between row B and D ? I expected row D to go up and take the place of row C.
I'm testing on a physical device so here's a quick paint of the result:
I expected the result to behave like this html table:
<table>
<tbody>
<tr>
<td rowspan="3" style="width: 70px; background-color: red;">A</td>
<td style="width: 500px; background-color: green;">B</td>
</tr>
<tr>
<td style="display: none; background-color: blue;">C</td>
</tr>
<tr>
<td style="background-color: orange;">D</td>
</tr>
</tbody>
</table>
Here's a snip of the html result:
That is because you have defined a GridLayout with 3 rows and you set the label D to the third row. Even when the label C is collapsed, its place won't be taken up.
If you would like to have a layout exactly as the second picture, then I suggest this:
<GridLayout columns="70, *" rows="auto">
<Label row="0" col="0" text="A" style="background-color: red;"></Label>
<StackLayout row="0" col="1">
<Label text="B" style="background-color: green;"></Label>
<Label text="C" visibility="collapse" style="background-color: blue;"></Label>
<Label text="D" style="background-color: orange"></Label>
</StackLayout>
</GridLayout>
P/s: if you put the label C back to visible, the layout will resize itself also