Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

IOS design of Popups and radiobuttons

MasterOfXamarinMasterOfXamarin Member ✭✭✭
edited October 16 in Xamarin.iOS

Welcome, I am struggling with a problem. I need to create some popups in ios application. I need to achive radiobutton which is on the image below

Second thing is a popup, especially the blue "Tick" which I have seen is several popups along ios applications, is there any way to achive this in xamarin ?

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited October 19

    Try to customize a custom radio button with a circle view and an UILabel. Add gesture to the 'CustomRadioButton' and detect the tap event to change the background of the circleView.

    Check the code:
    Custom radio button class

    public class CustomRadioButton : UIView
    {
        private CircleView circleView;
        private UILabel buttonTitle;
    
        public bool State
        {
            get
            {
                return circleView.State;
            }
            set
            {
                circleView.State = value;
            }
        }
    
        public CustomRadioButton(CGPoint point, string title)
        {
            this.Frame = new CGRect(point, new CGSize(120, 60));
            circleView = new CircleView(new CGRect(45, 30, 30, 30));
            buttonTitle = new UILabel(new CGRect(0, 0, 120, 30));
            buttonTitle.Text = title;
            buttonTitle.TextAlignment = UITextAlignment.Center;
            this.AddSubview(circleView);
            this.AddSubview(buttonTitle);
            UITapGestureRecognizer tapGR = new UITapGestureRecognizer(() => {
                State = !State;
                //...
            });
            this.AddGestureRecognizer(tapGR);
        }
    }
    

    CirecleView class

    class CircleView : UIView
    {
        private bool state = false;
        public bool State
        {
            get
            {
                return state;
            }
            set
            {
                state = value;
                this.SetNeedsDisplay();
            }
        }
    
        public CircleView(CGRect frame)
        {
            this.BackgroundColor = UIColor.Clear;
            this.Frame = frame;
        }
    
        public override void Draw(CoreGraphics.CGRect rect)
        {
            CGContext con = UIGraphics.GetCurrentContext();
    
            float padding = 5;
            con.AddEllipseInRect(new CGRect(padding, padding, rect.Width - 2 * padding, rect.Height - 2 * padding));
            con.StrokePath();
    
            if (state)
            {
                float insidePadding = 8;
                con.AddEllipseInRect(new CGRect(insidePadding, insidePadding, rect.Width - 2 * insidePadding, rect.Height - 2 * insidePadding));
                con.FillPath();
            }
        }
    }
    

    Refer to:
    https://forums.xamarin.com/discussion/128702/creating-radio-button-group-xamarin-ios

Sign In or Register to comment.