兩個按鈕切換
1.第一個按鈕一開始就是選中狀態(tài)报强,所以要調(diào)用[self btnClick:btn]方法瞒御。
2.如果點擊了selected = YES的按鈕钾腺,就什么都不做泥耀。
3.如果點擊了selected = NO的按鈕饺汹,就讓當前點擊的按鈕selected = YES,另一個按鈕的selected = NO痰催。
// 按鈕寬度
CGFloat btnWidth = (slideWidth - 60) / 2;
// 歷史周刊按鈕
RXBaseButton *weeklyMagaBtn = [RXBaseButton buttonWithType:UIButtonTypeCustom];
weeklyMagaBtn.tag = 200;
[weeklyMagaBtn setBackgroundImage:[UIImage imageNamed:@"歷史周刊按鈕"] forState:UIControlStateNormal];
[weeklyMagaBtn setBackgroundImage:[UIImage imageNamed:@"歷史周刊選中"] forState:UIControlStateSelected];
[weeklyMagaBtn setTitle:@"歷史周刊" forState:UIControlStateNormal];
weeklyMagaBtn.size = CGSizeMake(btnWidth , 40);
weeklyMagaBtn.x = 15;
weeklyMagaBtn.y = 54;
[self.view addSubview:weeklyMagaBtn];
self.weeklyMagaBtn = weeklyMagaBtn;
[weeklyMagaBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self btnClick:weeklyMagaBtn]; // 第一個按鈕默認選中
// 類型分類按鈕
RXBaseButton *typeMagaBtn = [RXBaseButton buttonWithType:UIButtonTypeCustom];
typeMagaBtn.tag = 201;
[typeMagaBtn setBackgroundImage:[UIImage imageNamed:@"歷史周刊按鈕"] forState:UIControlStateNormal];
[typeMagaBtn setBackgroundImage:[UIImage imageNamed:@"歷史周刊選中"] forState:UIControlStateSelected];
[typeMagaBtn setTitle:@"類型分類" forState:UIControlStateNormal];
typeMagaBtn.size = CGSizeMake(btnWidth , 40);
typeMagaBtn.x = 45 + btnWidth;
typeMagaBtn.y = 54;
[self.view addSubview:typeMagaBtn];
self.typeMagaBtn = typeMagaBtn;
[typeMagaBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
//RXLog(@"按鈕的位置是%f,%f, %f", slideWidth, loginBtn.x, loginBtn.y);
// 點擊按鈕
-(void)btnClick:(UIButton *)btn這個方法為
if(btn.selected == NO){
if(btn.tag == 200){
self.typeMagaBtn.selected = NO;
}else{
self.weeklyMagaBtn.selected = NO;
}
btn.selected = YES;
}