Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkbox control for iOS application

Is there any checkbox control in the object library for iOS applications? The nearest thing I see is the switch control, which can take a boolean value.

like image 870
Firdous Avatar asked Feb 22 '12 07:02

Firdous


People also ask

What is the toggle button for Apple?

A toggle lets people choose between a pair of opposing states, like on and off, using a different appearance to indicate each state. Different platforms can support various toggle styles. For example, iOS, iPadOS, macOS, and watchOS support the switch toggle style, whereas only macOS supports the checkbox style.

What is radio button Iphone?

A radio button displays the setting of something in your application and is part of a group in which only one button can be on at a time. Use a group of radio buttons to choose among several options which are mutually exclusive.

How do I turn the toggle off on my Iphone?

Go to Settings > Accessibility > Switch Control and turn the setting on or off.


2 Answers

You can use the selected state of a UIButton, set different images (or also texts) for differents (via code, or Interface Builder) :

[button setImage:[UIImage imageNamed:@"selected.png"]
        forState:UIControlStateSelected];
[button setImage:[UIImage imageNamed:@"unselected.png"]
        forState:UIControlStateNormal];

And in the touch up inside action :

- (IBAction)buttonTouched:(id)sender
{
    button.selected = !button.selected;
    // add other logic
}
like image 56
ıɾuǝʞ Avatar answered Oct 20 '22 01:10

ıɾuǝʞ


//define property of button

Declare Unchecked Image

- (void)viewDidLoad
{
    [_checkboxButton setBackgroundImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
}

Checked Image.

- (IBAction)buttonTapped:(id)sender
{
    if (_checkboxButton.selected == YES)
    {
        [_checkboxButton setBackgroundImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateSelected];
        _checkboxButton.selected = NO;
    }
    else
    {
        [_checkboxButton setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
        _checkboxButton.selected = YES;
    }
}
like image 20
Ketan Ubhada Avatar answered Oct 20 '22 01:10

Ketan Ubhada