#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate , UITableViewDataSource,UIScrollViewDelegate>
{
UIView *vieww;
UITableView *tablev;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"李鹏程";
self.view.backgroundColor = [UIColor whiteColor];
[self lpcbtn];
[self gundongshitu];
vieww = [[UIView alloc]initWithFrame:CGRectMake(260, 64+50+20, 150, 200)];
vieww.backgroundColor = [UIColor blueColor];
[self.view addSubview:vieww];
tablev = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 150, 200)];
tablev.delegate = self;
tablev.dataSource = self;
tablev.rowHeight = 70;
[vieww addSubview:tablev];
vieww.hidden = YES;
}
-(void)lpcbtn
{
NSMutableArray *mutabearr = [NSMutableArray arrayWithObjects:@"李鹏程",@"李鹏程",@"李鹏程",@"李鹏程",@"李鹏程",@"+", nil];
for (int i = 0; i < mutabearr.count; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
if (i == 0) {
btn.backgroundColor = [UIColor orangeColor];
}else if(i == 5)
{
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor greenColor] forState:UIControlStateSelected];
btn.titleLabel.font = [UIFont systemFontOfSize:30];
btn.backgroundColor = [UIColor lightGrayColor];
[btn addTarget:self action:@selector(lpcbtn:) forControlEvents:UIControlEventTouchUpInside];
btn.selected = NO;
}else{
btn.backgroundColor = [UIColor grayColor];
}
btn.frame = CGRectMake(i * 70, 64, 70, 50);
btn.tag = 100 + i;
[btn setTitle:[mutabearr objectAtIndex:i] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(jia:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
}
-(void)jia:(UIButton *)btn
{
for (int i = 0; i<5; i++)
{
//根据tag获取按钮
UIButton *btn1 = [self.view viewWithTag:100 + i];
if (btn.tag == btn1.tag)
{
btn1.backgroundColor = [UIColor orangeColor];
}
else
{
btn1.backgroundColor = [UIColor grayColor];
}
}
}
-(void)gundongshitu
{
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64 + 50, self.view.frame.size.width, self.view.frame.size.height - 64 - 50)];
//设置偏移量
scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 5, self.view.frame.size.height - 64 - 50);
//设置代理
scrollView.delegate = self;
scrollView.pagingEnabled = YES;
//设置tag值
scrollView.tag = 50;
scrollView.backgroundColor = [UIColor greenColor];
[scrollView setContentOffset:CGPointMake(self.view.frame.size.width, 0)];
[self.view addSubview:scrollView];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.tag == 50)
{
//根据当前视图的偏移量设置当前的按钮位置
for (int i=0; i<5; i++)
{
//根据tag获取
UIButton *btn1 = [self.view viewWithTag:100+i];
if (scrollView.contentOffset.x/self.view.frame.size.width == (btn1.tag - 100))
{
btn1.backgroundColor = [UIColor orangeColor];
}
else
{
btn1.backgroundColor = [UIColor grayColor];
}
}
}
}
-(void)lpcbtn:(UIButton *)sender
{
if (sender.tag == 105) {
if (sender.selected == YES) {
sender.selected = NO;
vieww.hidden = YES;
}else
{
sender.selected = YES;
vieww.hidden = NO;
}
}
}
//====数据源方法=====
//设置行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
//设置单元格 内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//根据可重用标识符查找
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//判断cell 如果没有创建cell
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
NSArray *arr = [NSArray arrayWithObjects:@"确认添加",@"确认删除",@"关闭", nil];
//设置 cell 内容
cell.textLabel.text = arr[indexPath.row];
cell.backgroundColor = [UIColor blueColor];
//返回cell
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0 ) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认添加" message:@"操作已成功" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:action];
[self.navigationController presentViewController:alert animated:YES completion:^{
}];
}else if (indexPath.row == 1)
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确认删除" message:@"操作已成功" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:action];
[self.navigationController presentViewController:alert animated:YES completion:^{
}];
}else
{
vieww.hidden = YES;
}
}
@end
下拉View
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...