IOSのグリーンのトグルボタンのデフォルトの色を変更するにはどうすればよいですか?XamarinはIOSのトグルボタンのデフォルトの色を設定します
2
A
答えて
2
スイッチのカスタムレンダリング(iOSのUISwitch)を作成し、そのOnTintColorプロパティを設定します。 PCLで
:iOS版で
public class CustomSwitch : Switch
{
}
:
[assembly: ExportRenderer(typeof(CustomSwitch), typeof(CustomSwitchRenderer))]
namespace xyz.iOS.CustomControlRenderers
{
public class CustomSwitchRenderer : SwitchRenderer
{
protected override void OnElementChanged (ElementChangedEventArgs<Switch> e)
{
base.OnElementChanged (e);
if (Control != null)
{
// do whatever you want to the UISwitch here!
Control.OnTintColor = UIColor.FromRGB (204, 153, 255);
}
}
}
}
あなたがAndroidプラットフォームでカスタムレンダリングを作成する必要はありませんアンドロイドのための任意のカスタマイズを必要としないので。
フォームの実装に対応するすべてのネイティブレンダリングのリストをhereから取得できます。 カスタムレンダリングの例はhereです。
0
@Rohitの答えに間違いはありませんが、間違いなく動作します。しかし、より良い解決法(この特定の場合)は、Effectsを使用することであることを指摘したいと思います。 Why?
あなたはそれで行くことに決めた場合、あなたの実装は次のようなものになります:
のiOSプロジェクトコード:
Constants.ResolutionGroupName
が定義されたばかりの文字列(例えば "MyCompanyの")、である
using UIKit;
using VisualStimulation.iOS.Effects;
using VisualStimulation.Utilities;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ResolutionGroupName(Constants.ResolutionGroupName)]
[assembly: ExportEffect(typeof(SwitchEffects), nameof(SwitchEffects))]
namespace VisualStimulation.iOS.Effects
{
public class SwitchEffects : PlatformEffect
{
protected override void OnAttached()
{
var switchControl = Control as UISwitch;
if (switchControl != null)
{
switchControl.OnTintColor = UIColor.FromRGB(204, 153, 255);
}
}
protected override void OnDetached()
{
}
}
}
を別のクラスで。
PCLコード:ContentPage
レベルで定義されeffect
名前空間に
<Switch>
<Switch.Effects>
<effects:SwitchEffects></effects:SwitchEffects>
</Switch.Effects>
</Switch>
:
using VisualStimulation.Utilities;
using Xamarin.Forms;
namespace VisualStimulation.Effects
{
public class SwitchEffects : RoutingEffect
{
public SwitchEffects() : base($"{Constants.ResolutionGroupName}.{nameof(SwitchEffects)}")
{
}
}
}
そして最後に、XAMLコード
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:effects="clr-namespace:<effect.class.namespace>;assembly=<nameOfYourAssembly>"
0
あなたはそれを変更したい場合はアプリ全体の (iOSのプロジェクトで)それはAppDelegate.csにFinishedLaunching方法であるファイルを実行する方法をトン方法:
UISwitch.Appearance.OnTintColor = UIColor.FromRGB(0xFF, 0x00, 0x00); // RED
全例:
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// switch
UISwitch.Appearance.OnTintColor = UIColor.FromRGB(0xFF, 0x00, 0x00);
// required Xamarin.Forms code
Forms.Init();
LoadApplication (new App());
return base.FinishedLaunching (app, options);
}
出典:https://developer.xamarin.com/guides/xamarin-forms/platform-features/ios/theme/#UISwitch
関連する問題
- 1. Ios - デフォルトのテキストの色とフォントのサイズを設定する
- 2. Xamarin iOSスライダの色
- 3. Xcode Interface Builderのデフォルトの色空間を設定します。
- 4. iOSのサファリサイトのレンダリングにデフォルトの100%ズームを設定します。
- 5. iOSスタイルのトグルボタン
- 6. デフォルトのiOSウェブクリップアイコンのタイトルを設定しますか?
- 7. XamarinのDatePickerダイアログの色を設定する方法は?
- 8. カスタムリボンタブのトグルボタンの値を設定する
- 9. Xcode/iOSのロケール固有のデフォルト設定
- 10. iosの設定からデフォルト値を設定する
- 11. プログレスバーのデフォルトの色を設定するには
- 12. R ggplot2でデフォルトのgeom_textの色を設定する方法は?
- 13. JButtonのデフォルトの背景色を設定する方法は?
- 14. XamarinフォームiOSステータスバーのテキストの色
- 15. Monotouchでアプリケーション全体のデフォルトのUILabelの色を設定します
- 16. Xamarinフォーム:ios内のラベルの最小高さを設定します
- 17. android 4.xのデフォルトのedittextの色を設定する方法
- 18. iOSのボタンのタイトルテキストを設定するXamarin
- 19. Xamarin iOS画像色合い色
- 20. Xamarinリストビューで異なる行の色を設定する方法
- 21. iOS - TTTAttributedLabelを使用して2色のテキストを設定する
- 22. Ionic build iosコマンドのデフォルト設定を変更するには?
- 23. QTextToSpeechデフォルトのQLocaleを設定します
- 24. デフォルトのロケールを設定します
- 25. デフォルトのWebDriver Serenityを設定します。
- 26. デフォルトのラジオボタンを設定します
- 27. iOSでビューの描画のテキストの色を設定しました
- 28. Xamarin iOSのUIPickerViewにリストを設定する
- 29. xamarin iosでUITableViewCellの背景色をカスタマイズする方法は?
- 30. Androidトグルボタン - 背景色
ありがとう! – sylmz
ようこそ。 :-) –