我试图在Nativescript Angular项目的文本字段中获取图标。当我尝试完成此操作时,它会定位在字段外,或者至少看起来是这样。我看过一些代码示例(sample),但是当我自己尝试时,它将无法正常工作。
<GridLayout rows="auto, auto, auto, auto, auto" class="container" loaded="onLoaded()">
<app-eon-colors-top></app-eon-colors-top>
<StackLayout row="1" class="logo">
<Image src="res://live_logo"></Image>
</StackLayout>
<Stacklayout row="2" class="form">
<StackLayout>
<TextField #userName hint="Användarnamn" class="field" [text]="userInput.username" required [isEnabled]="!(processing$ | async)" keyboardType="email" autocapitalizationType="none" autocorrect="false" (textChange)="setUsername($event)" (focus)="focusUserName($event)"
(returnPress)="focusPassword()"></TextField>
</StackLayout>
<GridLayout columns="auto, *, auto">
<Label col="0" class="icon fa-regular" [text]="lockIcon"></Label>
<TextField col="1" #password hint="Lösenord" class="field" [text]="userInput.password" required [isEnabled]="!(processing$ | async)" secure="true" autocapitalizationType="none" autocorrect="false" (textChange)="setPassword($event)" (focus)="focusPassword($event)"
(returnPress)="submit()">
</TextField>
<Label col="2" class="icon fa-regular" [text]="activePasswordShowHideIcon" ios:style="padding-bottom: 35" (tap)="showHidePassword()"></Label>
</GridLayout>
<Label class="error-msg" textWrap="true" *ngIf="(errors$ | async)" [text]="errorTxt"></Label>
<Button class="login-button" text="LOGGA IN" [isEnabled]="!(processing$ | async)" (tap)="submit()"></Button>
</Stacklayout>
<ActivityIndicator rowSpan="5" color="#23a1b0" [busy]="(processing$ | async)" width="100" height="100" class="activity-indicator"></ActivityIndicator>
</GridLayout>
答案 0 :(得分:1)
您将必须删除TextField随附的默认背景/边框,并将边框应用于父容器,以使其看起来像TextField的一部分。
示例
<StackLayout class="form">
<GridLayout class="m-10 input-border" columns="*,auto">
<TextField col="0" class="input"></TextField>
<Label col="1" class="h3" text="" verticalAlignment="center"></Label>
</GridLayout>
</StackLayout>
答案 1 :(得分:0)
我最终将 TextField 的边距设置为负值。不确定这是否是正确的方法。但它似乎是我想要的。
<StackLayout orientation="horizontal">
<TextField text="Test"
(tap)="onCollectionDateTap($event)"
style="width: 200; margin-right:-15;"></TextField>
<Label class="fa" text="" ></Label>
</StackLayout>