public override void ViewDidLoad() { base.ViewDidLoad(); /// An animated toggle with different ON and OFF animations. LOTAnimatedSwitch toggle1 = LOTAnimatedSwitch.SwitchNamed("Switch"); toggle1.SetProgressRangeForOnState(0.5f, 1.0f); toggle1.SetProgressRangeForOffState(0f, 0.5f); toggle1.ValueChanged += Switch_ValueChanged; this.View.AddSubview(toggle1); /// An animated 'like' or 'heart' button. /// Clicking toggles the Like or Heart state. /// The animation runs from 0-1, progress 0 is off, progress 1 is on LOTAnimatedSwitch heartIcon = LOTAnimatedSwitch.SwitchNamed("TwitterHeart"); heartIcon.ValueChanged += Switch_ValueChanged; this.View.AddSubview(heartIcon); /// This is a switch that also has a Disabled state animation. /// When the switch is disabled then the disabled layer is displayed. LOTAnimatedSwitch statefulSwitch = LOTAnimatedSwitch.SwitchNamed("Switch_States"); statefulSwitch.SetProgressRangeForOnState(1f, 0f); statefulSwitch.SetProgressRangeForOffState(0f, 1f); statefulSwitch.SetLayerName("Button", UIControlState.Normal); statefulSwitch.SetLayerName("Disabled", UIControlState.Disabled); // Changes visual appearance by switching animation layer to "Disabled" statefulSwitch.Enabled = false; // Changes visual appearance by switching animation layer to "Button" statefulSwitch.Enabled = true; statefulSwitch.ValueChanged += Switch_ValueChanged; statefulSwitch.ValueChanged += Switch_ValueChanged; this.View.AddSubview(statefulSwitch); // Layout toggle1.Center = new CGPoint(this.View.Bounds.GetMidX(), 90); heartIcon.Bounds = new CGRect(0, 0, 200, 200); heartIcon.Center = new CGPoint(this.View.Bounds.GetMidX(), toggle1.Frame.GetMaxY() + (heartIcon.Bounds.Size.Height * 0.5)); statefulSwitch.Center = new CGPoint(this.View.Bounds.GetMidX(), heartIcon.Frame.GetMaxY() + (statefulSwitch.Bounds.Size.Height * 0.5)); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); LOTAnimatedSwitch lottie = LOTAnimatedSwitch.SwitchNamed("nightmode"); float state1 = Semdelion.Core.User.Settings.ModeNight ? 0.9f : 0.5f; float state2 = Semdelion.Core.User.Settings.ModeNight ? 0.5f : 0.1f; lottie.SetProgressRangeForOnState(state2, state1); lottie.SetProgressRangeForOffState(state1, state2); lottie.ContentMode = UIViewContentMode.ScaleToFill; lottie.Frame = new CoreGraphics.CGRect(0, 0, ThemeView.Frame.Width, ThemeView.Frame.Height); ThemeView.AddSubview(lottie); lottie.ValueChanged += (sender, e) => { var window = UIApplication.SharedApplication.Windows[0]; window.OverrideUserInterfaceStyle = Semdelion.Core.User.Settings.ModeNight ? UIUserInterfaceStyle.Light : UIUserInterfaceStyle.Dark; Semdelion.Core.User.Settings.ModeNight = !Semdelion.Core.User.Settings.ModeNight; }; }