/// <summary> /// The focus has moved to a new control. Track the focused button /// if it's one of ours. /// </summary> /// <param name="context">Focus update context.</param> /// <param name="coordinator">Focus animation coordinator.</param> public override void DidUpdateFocus(UIFocusUpdateContext context, UIFocusAnimationCoordinator coordinator) { base.DidUpdateFocus(context, coordinator); var buttons = Subviews.Cast <MenuButton>().ToList(); for (int i = 0; i < buttons.Count; i++) { if (context.NextFocusedView == buttons[i]) { FocusedButtonIndex = i; } } }
/// <summary> /// Layouts the buttons so they are centered horizontally and vertically. /// </summary> private void LayoutButtons() { var buttons = Subviews.Cast <MenuButton>().ToList(); nfloat totalWidth = 0; if (buttons.Count == 0) { return; } // // Determine the total width we will be using. // buttons.ForEach(b => { b.SizeToFit(); totalWidth += b.Frame.Width; }); // // Get our starting position of the first button. // nfloat x = (Bounds.Width - totalWidth) / 2.0f; // // Position each button sequentially. // buttons.ForEach(b => { nfloat y = Bounds.Size.Height / 4.0f; b.Frame = new CGRect(x, y, b.Frame.Size.Width, Bounds.Size.Height / 2.0f); x += b.Frame.Size.Width; }); }