IOS custom View -- checkbox

Source: Internet
Author: User
========================================================== =============================== Original blog, reprinted please declare the source of Electronic coffee (original id blue rock) ========================================================== ============================== there is no checkbox or radio button in iOS, this is quite speechless for kids shoes that have done Android. It doesn't matter. We write a view to implement our own single and check boxes. First, add two images to your resource. One is the selected status of the button, and the other is the unselected status, named unchecked.pngand checked.png respectively. The following code is displayed. I believe you can understand it ., If you have any questions, please leave a message. Uicheckbox. h
#import <UIKit/UIKit.h>@interface UICheckBox : UIButton@end
Uicheckbox. m

#import "UICheckBox.h"@implementation UICheckBox- (id)initWithFrame:(CGRect)frame{    self = [super initWithFrame:frame];    if (self) {       [self setBackGroundImage];    }    return self;}- (void)setBackGroundImage {    [self setBackgroundImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];    [self setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateSelected];            [self addTarget:self action:@selector(touchUIInside:) forControlEvents:UIControlEventTouchUpInside];}-(id)initWithCoder:(NSCoder *)aDecoder{    self =  [super initWithCoder:aDecoder];    if (self) {        [self setBackGroundImage];    }    return self;}-(IBAction)touchUIInside:(id)sender{   UICheckBox* cb= (UICheckBox*)sender;    cb.selected = !cb.selected;      }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.