【代码笔记】iOS-4个可以单独点击的button

一,效果图。

【代码笔记】iOS-4个可以单独点击的button

二,工程图。

【代码笔记】iOS-4个可以单独点击的button

三,代码。

ViewController.m

【代码笔记】iOS-4个可以单独点击的button
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. //初始化背景图
[self addBackGroundView]; }
#pragma -mark -functions
//初始化背景图
-(void)addBackGroundView
{
//4个连着的button
for (int i=0; i<4; i++) { UIButton *chooseButton=[UIButton buttonWithType:UIButtonTypeCustom];
chooseButton.frame=CGRectMake(0+80*i,50, 80, 38);
chooseButton.tag=i;
if (i==0) {
[chooseButton setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getno1"] forState:UIControlStateNormal];
}else if (i==1){
[chooseButton setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getyes1"] forState:UIControlStateNormal];
}else if (i==2){
[chooseButton setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workno1"] forState:UIControlStateNormal];
}else if (i==3){
[chooseButton setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workyes1"] forState:UIControlStateNormal];
}
[chooseButton setBackgroundColor:[UIColor clearColor]];
[chooseButton addTarget:self action:@selector(doClickChooseButton:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:chooseButton]; } }
#pragma -mark -doClickActions
//4个按钮
-(void)doClickChooseButton:(UIButton *)btn
{
NSLog(@"---doClickChooseButton--");
if (btn.tag==0) {
if (btn.selected==NO) {
[btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getno2"] forState:UIControlStateNormal];
btn.selected=YES;
}else{
[btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getno1"] forState:UIControlStateNormal];
btn.selected=NO;
} }else if (btn.tag==1){
if (btn.selected==NO) {
[btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getyes2"] forState:UIControlStateNormal];
btn.selected=YES;
}else{
[btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_getyes1"] forState:UIControlStateNormal];
btn.selected=NO;
} }else if (btn.tag==2){
if (btn.selected==NO) {
[btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workno2"] forState:UIControlStateNormal];
btn.selected=YES;
}else{
[btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workno1"] forState:UIControlStateNormal];
btn.selected=NO;
} }else if (btn.tag==3){
if (btn.selected==NO) {
[btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workyes2"] forState:UIControlStateNormal];
btn.selected=YES;
}else{
[btn setBackgroundImage:[UIImage imageNamed:@"shoplist_tab_workyes1"] forState:UIControlStateNormal];
btn.selected=NO;
} } } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
【代码笔记】iOS-4个可以单独点击的button
上一篇:LVS 介绍以及配置应用


下一篇:Java基础知识总结--反射