選擇是否記住密碼整體button,記住密碼整體button
:
工程圖:
此代碼需要加入第三方庫BECheckBox.
代碼:
#import "RootViewController.h"//加入標頭檔#import "BECheckBox.h"@interface RootViewController ()@end@implementation RootViewController@synthesize passwordCheck;- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //隱藏導航條 self.navigationController.navigationBarHidden=YES; //忘記密碼按鈕 BECheckBox *passCheckBox=[[BECheckBox alloc]initWithFrame:CGRectMake(61, 55, 80, 30)]; [passCheckBox setTitle:@"記住密碼" forState:UIControlStateNormal]; [passCheckBox setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; passCheckBox.titleLabel.font=[UIFont systemFontOfSize:16]; [passCheckBox setTarget:self fun:@selector(passCheckBoxClick:)]; passCheckBox.backgroundColor=[UIColor clearColor]; self.passwordCheck=passCheckBox; [self.view addSubview:self.passwordCheck]; }//記住密碼點擊-(void)passCheckBoxClick:(id)sender{ if ([self.passwordCheck isChecked]) { NSLog(@"記住密碼"); } else { NSLog(@"取消記住密碼"); }}