【问题标题】:How to style the day/month/year selectors of a RadDataForm Datepicker如何设置 RadDataForm Datepicker 的日/月/年选择器的样式
【发布时间】:2019-06-03 08:02:22
【问题描述】:

我在 Nativescript-Angular 应用程序中有一个 RadDataForm。

这个 RadDataForm 显示了我的一个属性的 Datepicker。

我已经阅读了有关styling the components of a RadDataForm 的信息,但它缺少有关如何设置更改日期时显示的“轮子文本”样式的部分。 (或者我错过了什么?)

它们保持黑色,但我需要另一种颜色(即白色)

【问题讨论】:

标签: nativescript nativescript-angular


【解决方案1】:

根据Apple Docs

UIDatePicker 的外观不可自定义。

您应该使用自动布局将日期选择器集成到您的布局中。 虽然日期选择器可以调整大小,但它们应该在他们的 内在内容大小。

但是,您可以设置的东西很少。我为here 创建了一个游乐场。

在你的 html 中

<RadDataForm [source]="album" (editorUpdate)="dfEditorUpdate($event)">
            <TKEntityProperty tkDataFormProperty name="albumName" displayName="Name of Album"
                index="0"></TKEntityProperty>
            <TKEntityProperty tkDataFormProperty name="bandName" displayName="Name of Band"
                index="1"></TKEntityProperty>
            <TKEntityProperty tkDataFormProperty name="year" displayName="Release Year"
                index="2"></TKEntityProperty>
            <TKEntityProperty tkDataFormProperty name="myRating" displayName="My Rating"
                index="3"></TKEntityProperty>
            <TKEntityProperty tkDataFormProperty name="owned" displayName="Do I Own This?"
                index="4"></TKEntityProperty>
            <TKEntityProperty tkDataFormProperty name="birthDate" index="5">
                <TKPropertyEditor tkEntityPropertyEditor type="DatePicker">
                    <TKPropertyEditorStyle tkPropertyEditorStyle strokeColor="#00695c"
                        strokeWidth="2" fillColor="#4db6ac" labelHidden="false"
                        labelTextSize="18" ios:labelFontName="Times New Roman"
                        android:labelFontName="sans-serif-light"
                        labelFontStyle="Italic" labelPosition="Left"
                        labelWidth="60" labelTextColor="#ffffff"></TKPropertyEditorStyle>
                </TKPropertyEditor>
            </TKEntityProperty>
        </RadDataForm>

在您的 .ts 文件中

import { Color } from "tns-core-modules/color";
import { EntityProperty, DataFormEventData, RadDataForm } from "nativescript-ui-dataform";

let colorLight = new Color("#ff0000");
let colorWhite = new Color("#ffffff");
let colorDark = new Color("#4CAF50");
let colorGray = new Color("#F9F9F9");

public dfEditorUpdate(args: DataFormEventData) {
        if (androidApplication) {
            switch (args.propertyName) {
                case "appVolume":
                    break;
            }
        } else {
            const entityProperty: EntityProperty =
                (<RadDataForm>args.object).getPropertyByName(args.propertyName);

            switch (entityProperty.editor.type) {
                case "DatePicker":

                    const coreEditor = args.editor.editor;
                    coreEditor.subviews[0].backgroundColor = colorLight.ios;
                    coreEditor.subviews[0].setValueForKeyPath(colorWhite.ios, 'textColor');


                    break;

            }
        }
    }

【讨论】:

  • 对于ios,可以参考这个答案。 stackoverflow.com/a/33789261/3840213
  • 显然这只会使日期选择器的背景变成红色。
  • 找到了 DatePicker 的解决方案.....但我在 UIPickerView 上苦苦挣扎。 play.nativescript.org/?template=play-ng&id=Nj15Dj&v=2
  • 是的,我也尝试了其他几个选项,例如entityProperty.editor.propertyEditorStyle.strokeColor = new Color("orange"); 只改变表格中的笔触颜色
  • 我认为当用户点击 DatePicker 时,它会打开 Spinner,我们需要找到一种方法来更改 textColor 那里
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-22
  • 1970-01-01
  • 2011-09-13
  • 1970-01-01
相关资源
最近更新 更多