How center using stacklayout and also depends of an image? - xamarin.forms

i want to center my image and label, and the label have to is center depending of my image, for example:
*****************************
* *
* ----- *
* - i -'label'. *
* ----- *
* *
*****************************
i have this code:
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Image Source=".image.png" WidthRequest="5">
</Image>
<Label Text="image"/>
</StackLayout>
but i get so:
*****************************
* ------'label'. *
* - i - *
* ------ *
*****************************

use VerticalOptions
<Label VerticalOptions="Center" Text="{Binding DateFormat}"/>

Related

Xamarin forms: Image entry is not working as expected in android

I follow this blog for adding an image inside of an entry. It was working fine in android and IOS initially.
But when I changed the android target version and target framework to 9.0 this feature start breaking. Please see the following screenshot.
The image inside entry is zoomed in and not showing as expected. I have updated all the android SDK but no change in the output. Should I do anything else for solving this issue in android?
My Code:
<StackLayout
HorizontalOptions="FillAndExpand"
Padding="5"
VerticalOptions="CenterAndExpand">
<Label
Text="Email"
TextColor="Black"
FontSize="Medium"/>
<Frame
CornerRadius="15"
Padding="2,-3,-3,-3"
HasShadow="false"
BorderColor="#c0eefb"
OutlineColor="#c0eefb">
<local:ImageEntry
Image="ic_email_entry_image_xx"
x:Name="username_entry"
Text="charlesgeorge.admin"
FontSize="Medium"
HorizontalOptions="FillAndExpand"
Keyboard="Email"/>
</Frame>
<Label
Text="Password"
Margin="0,5,0,0"
TextColor="Black"
FontSize="Medium"/>
<Frame
CornerRadius="15"
Padding="2,-3,-3,-3"
HasShadow="false"
BorderColor="#c0eefb"
OutlineColor="#c0eefb">
<local:ImageEntry
Image="ic_password_entry_image_xx"
x:Name="password_entry"
FontSize="Medium"
Text="admingeorge1#"
HorizontalOptions="FillAndExpand"
IsPassword="True"/>
</Frame>
<Button
Text="SIGN IN"
Margin="0,15,0,15"
HeightRequest="40"
WidthRequest="180"
FontSize="Large"
TextColor="White"
HorizontalOptions="CenterAndExpand"
BackgroundColor="#26B5D6"
Clicked="SignInButtonCliked"
BorderRadius="20"/>
</Button>
</StackLayout>
If I downgrade the version from 9.0(pie) to 8.1(oreo), the UI will work as expected. Why in 9.0 it is not working?
After Android 9.0(API 28) , you should provide more size of image asset .
Solution 1:
Put the same image in Drawable and xxx-hdpi,xxx-mdpi and so on .
Solution 2:
You can handle the different logic in different version of Android .
in ImageEntryRenderer
private BitmapDrawable GetDrawable(string imageEntryImage)
{
int resID = Resources.GetIdentifier(imageEntryImage, "drawable", this.Context.PackageName);
var drawable = ContextCompat.GetDrawable(this.Context, resID);
var bitmap = ((BitmapDrawable)drawable).Bitmap;
if(Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.P)
{
return new BitmapDrawable(Resources, Bitmap.CreateScaledBitmap(bitmap, element.ImageWidth * 2, element.ImageHeight * 2, true));
}
return new BitmapDrawable(Resources, Bitmap.CreateScaledBitmap(bitmap, element.ImageWidth , element.ImageHeight , true));
}

Get the message from assert in symfony template

I have a question related to Assert form validation in symfony. So I have :
/**
* #ORM\Column(type="string")
* #Assert\NotBlank(message="client.firstName.notBlank")
* #Assert\Length(
* min = 2,
* max = 50,
* minMessage = "client.firstName.invalid",
* maxMessage = "client.firstName.invalid"
* )
* #Assert\Regex(
* pattern = "/^[0-9]+$/i",
* htmlPattern = "^[0-9]+$",
* message="client.firstName.regex"
* )
*/
protected $firstName;
And in validators.yml :
client:
firstName:
notBlank: 'Not Blank'
invalid: 'Invalid'
regex: 'Regex'
In form I have :
<div class="form-group">
{{ form_label(form.firstName) }}
{{ form_widget(form.firstName) }}
<div class="invalid-feedback">
{{ 'client.firstName'|trans({}, 'validators') }}
</div>
</div>
When I try to submit the form I get the message : client.firstName. I need a way to get message from assert. Can you help me please ? Thx in advance.
You need add one other file for each your assert messages:
# app/Resources/translations/validators.en.yml
client.firstName.notBlank: Please enter your firt name.
......
I think this is not necessary:
<div class="invalid-feedback">
{{ 'client.firstName'|trans({}, 'validators') }}
</div>

best way customize field_error in symfony 3

i have a entity with path field
/**
* #var string
* #Assert\NotBlank(message="Please, upload scontrino/fattura della stufa acquistata.")
* #Assert\File(mimeTypes={ "application/pdf","image/png" ,"image/jpg","image/jpeg" })
* #ORM\Column(name="path_file", type="string", length=255)
*/
private $path;
i have this field in a form
->add('path', FileType::class, array('data_class' => null))
;
and in the twig file
<div class="row">
<div class="input-field col s12 ">
{{ form_errors(form.path) }}
{{ form_widget(form.path) }}
</div>
</div>
when i press submit button and i put i not allowed file now my message is
Il mime type del file non รจ valido ("application/zip"). I tipi permessi sono "application/pdf", "image/png", "image/jpg", "image/jpeg".
I want to change that message but i don't understand the best way to do that.
If i must do it in entity file or in form file or in twig file
You have to add:
mimeTypesMessage = "with the text you want", in the #Assert\File
in your #Assert\File of your entity
/**
* #var string
* #Assert\NotBlank(message="Please, upload scontrino/fattura della stufa acquistata.")
* #Assert\File(mimeTypes={ "application/pdf","image/png" ,"image/jpg","image/jpeg" }, mimeTypesMessage = "with the text you want")
* #ORM\Column(name="path_file", type="string", length=255)
*/
The symfony Reference

In angular2 & nativescript the *ngFor display array's elements on top of each other

I am populating an array with user's input and would like to render on the same page, the data from that array. I m using *ngFor to do that but it displays the elements on top of each other.
The html is:
<Gridlayout class="main-container" columns="auto" rows="auto,auto,auto">
<StackLayout exampleTitle toggleNavButton row="0" class="set-hour">
<!-- >> creating-timepicker-html -->
<timePicker class="example-container" #timePicker (loaded)="configure(timePicker)" verticalAlignment="center"></timePicker>
<Button text="Add hour" (tap)="onTap()"></Button>
<!-- << creating-timepicker-html -->
</StackLayout>
<StackLayout row="1" class="hour" *ngFor="let hour of hours">
<Label [text]='hour.hour'></Label>
<Label [text]='hour.minute'></Label>
</StackLayout>
</Gridlayout>
the ts is:
import { Component, OnInit, ViewChild, ElementRef} from "#angular/core";
import { UserService} from "../../../services/user.service";
import { TimePicker } from "ui/time-picker";
import { HoursModel } from "../../../models/hours.model";
#Component({
selector: "hours",
templateUrl:"components/profile/hours/hours.component.html",
styleUrls:["components/profile/hours/hours.component.css"]
})
export class HoursComponent implements OnInit{
#ViewChild("timePicker") tp: ElementRef;
public hours:Array<HoursModel>=[];
public index:number=0;
constructor(){}
ngOnInit(){}
configure(timePicker: TimePicker) {
timePicker.hour = 21;
timePicker.minute = 0;
}
onTap() {
let time =this.tp.nativeElement;
this.hours.push(<HoursModel>{id:this.index,hour:time.hour,minute:time.minute});
console.log(JSON.stringify(this.hours));
this.index++;
}
}
did you try using an ObservableArray ? https://docs.nativescript.org/cookbook/data/observable-array
also you could try the ChangeDetectorRef detectCahnges() method
It seems that you would like to display data within a list.
Try to use this code:
<ListView [items]="hours | async" >
<ng-template let-item="hour" >
<StackLayout>
<Label [text]='hour.hour'></Label>
<Label [text]='hour.minute'></Label>
</StackLayout>
</ng-template>
</ListView>
With your current code you continuously add the data on top of each other, because the parent component is the page itself.
List view is the UI elements that you search.

fosuser bundle - changing password pattern

I want to change the password pattern of FosUser Bundle.. (lets say, i will require the password to be minumum of 6 characters which also require 1 letter and 1 number. Where do i set this?
Yuo can do this in FosUserBundle validator.
Take a look at this file:
/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation.xml
Particularly:
<property name="plainPassword">
<constraint name="NotBlank">
<option name="message">fos_user.password.blank</option>
<option name="groups">Registration</option>
</constraint>
<constraint name="MinLength">
<option name="limit">2</option>
<option name="message">fos_user.password.short</option>
<option name="groups">
<value>Registration</value>
<value>Profile</value>
</option>
</constraint>
</property>
I don't know (but I suppose that I'm right) if exists a constraint of type "1 letter and 1 number".
In that case, you have to "build" it yourself and use in the same way you use the NotBlank and MinLenght constraint of this example
I've add into User entity
// src/Acme/AcmeBundle/Entity/User.php
....
class User extends BaseUser{
....
/**
* #Assert\NotBlank(message="fos_user.username.blank", groups={"Registration", "Profile"})
* #Assert\Length(min=5, max="255",
* minMessage="fos_user.username.short", maxMessage="fos_user.username.long",
* groups={"Registration", "Profile"})
*/
protected $username;
/**
* #Assert\NotBlank(message="fos_user.password.blank", groups={"Registration", "ResetPassword", "ChangePassword"})
* #Assert\Length(min=6,
* minMessage="fos_user.password.short",
* groups={"Registration", "Profile", "ResetPassword", "ChangePassword"})
*/
protected $plainPassword;

Resources