3

I want to add checkboxes and have a title for each checkbox and have if certain boxes are checked then it displays certain texts like

if box 1 then displays text1

if box 2 is selected then displays text2

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
Sandeep
  • 41
  • 1
  • 1
  • 3
  • I have created by own UI element called `UICheckBox` that basically has two different images one when checked and another when it isn't checked, you could also do this using a custom `UIButton` by changing the image for the different states one for selected and one for normal. – Popeye Apr 23 '13 at 11:03
  • Have you tried anything? Where are you actually stuck? – David Rönnqvist Apr 23 '13 at 11:04
  • check this ... http://stackoverflow.com/questions/5368196/how-create-simple-checkbox – ajithmn89 Apr 23 '13 at 11:04
  • accept one of answer if you found it useful :) – Pratik B Apr 24 '13 at 04:26

3 Answers3

7

Try this ,

UIButton *buttonCheckbox = [[UIButton alloc] initWithFrame:CGRectMake(10, 12,20, 20)];  

[buttonCheckbox addTarget:self action:@selector(toggleButton:) forControlEvents: UIControlEventTouchUpInside];

- (void)toggleButton: (id) sender
{
   UIButton *tappedButton = (UIButton*)sender;

   NSLog(@"%d",tappedButton.tag);
   if([tappedButton.currentImage isEqual:[UIImage imageNamed:@"checkbox.png"]])
  {
   [sender  setImage:[UIImage imageNamed: @"checkbox-checked.png"] forState:UIControlStateNormal];
  }
    else
  {
   [sender  setImage:[UIImage imageNamed: @"checkbox.png"] forState:UIControlStateNormal];

  }  
Pratik B
  • 1,599
  • 1
  • 15
  • 32
0

You can find on Cocoa Controls some custom controls that implement checkboxes.

For example SSCheckBoxView is one of them. You can find it on github

alexcristea
  • 2,316
  • 16
  • 18
0

You are looking for UISwitch, it has the same functionality with checkbox but a different appearance. Otherwise you need to create your own checkbox possibly by customizing a UIButton.

To get updated when UISwitch's value changes you need to hook up its valueChanged event to an action.

-(IBAction) valueChanged:(UISwitch *) sender
{
     if(sender.on)
     {
         ...
     }
}
guenis
  • 2,520
  • 2
  • 25
  • 37