汽车

作者: 老公123 | 来源:发表于2018-10-19 20:00 被阅读0次

首先创建MainViewController 并且继承与UITabBarController

[self createTabBar];

}

- (void)createTabBar{

    NSArray *array=@[@"FuwuViewController",@"ShouyeViewController",@"KajuanViewController",@"GerenViewController"];

    NSArray*UnSelectedImageArray=@[@"首页",@"服务",@"卡卷",@"个人"];

    NSArray*SelectedImageArray=@[@"首页1",@"服务1",@"卡卷1",@"个人1"];

    //控制器数组

    NSMutableArray *ViewController=[[NSMutableArray alloc]init];

    //根据控制器的名称 创建相应的控制器 并添加到相应的数组里

    for(inti=0; i

        //字符串创建控制器

        UIViewController*VC=[[NSClassFromString(array[i])alloc]init];

        UINavigationController *NAV=[[UINavigationController alloc]initWithRootViewController:VC];

        //设置TabBar的选中图片和未选中图片

        NAV.tabBarItem.image=[[UIImage imageNamed:UnSelectedImageArray[i]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];

        NAV.title=UnSelectedImageArray[i];

        //将控制器添加到数组

        NAV.navigationBar.barTintColor=[UIColor colorWithRed:59/256.0 green:145/256.0 blue:233/256.0 alpha:1.0];

        [ViewControlleraddObject:NAV];

    }

    self.viewControllers=ViewController;

    self.selectedIndex = 1;

}

然后再创建控制器ShouyeViewController,FuwuViewController,KajuanViewController,GerenViewController    并继承与UIViewController

在控制器一写入

<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>

{

    UIScrollView * sc;

    NSArray* arr;

    UIPageControl * els;

    //定义一个定时器/ 

    NSTimer* time;

    //计数器

    inte;

    UICollectionView * clv;

    //图片

    NSArray* imgArr;

}

@property (nonatomic,strong)UITableView *table;

@property (nonatomic,strong)NSMutableArray *dataSource;

@property (strong, nonatomic) UIView *contentView;

@property (strong, nonatomic) UIButton *popBtn;

@end

staticNSString*clvReuseCell =@"11";

@implementationShouyeViewController

//-(void)viewDidAppear:(BOOL)animated{

//    self.navigationController.navigationBar.hidden = YES;

//}

//-(void)viewWillDisappear:(BOOL)animated{

//    self.navigationController.navigationBar.hidden = NO;

//

//}

- (void)viewDidLoad {

    [super viewDidLoad];

    [self.viewaddSubview:self.table];

    self.dataSource = [NSMutableArray new];

    [selfADDclv];

    self.title=@"服务";

    [selfsetn];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"top"] style:UIBarButtonItemStyleDone target:self action:nil];

}

-(void)setn{

    self.view.backgroundColor = [UIColor whiteColor];

    _contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 400, 300)];

    _contentView.backgroundColor = [UIColor clearColor];

    _popBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    _popBtn.frame=CGRectMake(0,250,200,50);

    _popBtn.backgroundColor = [UIColor greenColor];

    [_popBtn addTarget:self action:@selector(closeAndBack) forControlEvents:UIControlEventTouchUpInside];

    UIImageView *imageV = [[UIImageView alloc]initWithFrame:_contentView.bounds];

    imageV.image= [UIImageimageNamed:@"w1"];

    [_contentViewaddSubview:imageV];

    //    看看pop效果把下面这一句加上

    // [_contentView addSubview:_popBtn];

    [HWPopTool sharedInstance].shadeBackgroundType = ShadeBackgroundTypeSolid;

    [HWPopTool sharedInstance].closeButtonType = ButtonPositionTypeRight;

    [[HWPopTool sharedInstance] showWithPresentView:_contentView animated:YES];

}

- (void)closeAndBack {

    [[HWPopTool sharedInstance] closeWithBlcok:^{

        [self.navigationController popViewControllerAnimated:YES];

    }];

}

-(UITableView *)table{

    if(!_table) {

        _table = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

    }

    [_table registerNib:[UINib nibWithNibName:@"QQTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];

    _table.delegate=self;

    _table.dataSource = self;

    return _table;

}

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{

    return 2;

}

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

    QQTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    if(!cell) {

        cell = [[QQTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];

    }

    if(indexPath.row==0) {

        [selfnavTITLE];

    }

    elseif(indexPath.row==1){

        [selfnavTITLEADD];

    }

    returncell;

}

-(void)ADDclv{

    //创建流水布局(用了流水布局)

    UICollectionViewFlowLayout * fly = [UICollectionViewFlowLayout new];

    //格子大小

    fly.itemSize=CGSizeMake(100,100);

    //最小行间距

    fly.minimumLineSpacing = 1;

    //最小列间距

    fly.minimumInteritemSpacing = 1;

    //创建网格视图

    clv = [[UICollectionView alloc]initWithFrame:(CGRectMake(0, 170, self.view.frame.size.width, 200)) collectionViewLayout:fly];

    //数据源和代理

    clv.delegate =self;

    clv.dataSource = self;

    clv.backgroundColor = [UIColor lightGrayColor];

    //注册 网格的cell

    [clv registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:clvReuseCell];

    //添加

    [_table addSubview:clv];

}

-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{

    return 500;

}

-(void)abc{

    NSLog(@"%d",e);

    //set 方法->设置滚动视图偏移量

    [sc setContentOffset:CGPointMake(0, e*self.view.frame.size.height)];

    e++;

    if(e>3) {

        e=0;

    }

}

-(void)navTITLE{

            time = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(abc) userInfo:nil repeats:YES];

            //开启定时器

            [timefire];

            //1.创建滚动式图

            sc= [[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,500)];

            //签订代理

            sc.delegate=self;

            //2设.置滚动范围

            sc.contentSize = CGSizeMake(self.view.frame.size.width, 414);

            //添加视图

            [_tableaddSubview:sc];

            //添加分页

            sc.pagingEnabled=YES;

            //添加弹簧

            sc.bounces=NO;

            //禁用水平线

            sc.showsVerticalScrollIndicator = NO;

            //3.循环

            for(inti=0; i<4; i++) {

                arr=@[@"1",@"2",@"1",@"2"];

                UIImageView * vi = [[UIImageView alloc]initWithFrame:CGRectMake(0, i*self.view.frame.size.height, self.view.frame.size.width, 100)];

                vi.image= [UIImageimageNamed:arr[i]];

                [scaddSubview:vi];

            }

    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 130, 414, 30)];

    view.backgroundColor = [UIColor yellowColor];

    [_tableaddSubview:view];

    UILabel*lable = [[UILabelalloc]initWithFrame:CGRectMake(30,2,self.view.frame.size.width,30)];

    lable.text = @"公告:                                          亲爱的用户大人们,北";

    [viewaddSubview:lable];

    [UIView animateWithDuration:3 delay:2 options:UIViewAnimationOptionRepeat animations:^{

        //怎样的动画

        lable.frame = CGRectMake(self.view.frame.size.width, 0,self.view.frame.size.width , 30);

    }completion:^(BOOLfinished) {

        NSLog(@"动画结束");

    }];

}

-(void)navTITLEADD{

    UIView*view = [[UIViewalloc]initWithFrame:CGRectMake(0,330,414,20)];

    view.backgroundColor = [UIColor colorWithRed:245/256.0 green:245/256.0 blue:246/256.0 alpha:1.0];

    [_tableaddSubview:view];

    UILabel*lable = [[UILabelalloc]initWithFrame:CGRectMake(20,360,100,30)];

    lable.text=@"旗舰店";

    lable.textColor= [UIColorlightGrayColor];

    [_tableaddSubview:lable];

    UILabel*lable1 = [[UILabelalloc]initWithFrame:CGRectMake(330,360,100,30)];

    lable1.text=@"查看更多";

    [_tableaddSubview:lable1];

    UIImageView*image = [[UIImageViewalloc]initWithFrame:CGRectMake(0,400,200,200)];

    image.image= [UIImageimageNamed:@"b1"];

    [_tableaddSubview:image];

    UIImageView*image2 = [[UIImageViewalloc]initWithFrame:CGRectMake(200,400,200,200)];

    image2.image= [UIImageimageNamed:@"b2"];

    [_tableaddSubview:image2];

    UIView*view3 = [[UIViewalloc]initWithFrame:CGRectMake(0,630,414,20)];

    view3.backgroundColor = [UIColor colorWithRed:245/256.0 green:245/256.0 blue:246/256.0 alpha:1.0];

    [_tableaddSubview:view3];

    UILabel*lable3 = [[UILabelalloc]initWithFrame:CGRectMake(30,670,200,30)];

    lable3.textColor= [UIColorlightGrayColor];

    lable3.text=@"合作景点套票";

    [_tableaddSubview:lable3];

    UILabel*lable2 = [[UILabelalloc]initWithFrame:CGRectMake(250,670,200,30)];

    lable2.text=@"查看更多";

    [_tableaddSubview:lable2];

    UIImageView*image4 = [[UIImageViewalloc]initWithFrame:CGRectMake(0,700,414,100)];

    image4.image= [UIImageimageNamed:@"b4"];

    [_tableaddSubview:image4];

    UIImageView*image5 = [[UIImageViewalloc]initWithFrame:CGRectMake(0,800,414,100)];

    image5.image= [UIImageimageNamed:@"b5"];

    [_tableaddSubview:image5];

    UIImageView*image6 = [[UIImageViewalloc]initWithFrame:CGRectMake(0,900,414,100)];

    image6.image= [UIImageimageNamed:@"b6"];

    [_tableaddSubview:image6];

}

-(NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section{

    //格子的个数

    return 8;

}

-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{

    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:clvReuseCell forIndexPath:indexPath];

        UIImageView* imgV = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,60,60)];

        //数组

        imgArr = @[@"z1",@"z2",@"z3",@"z4",@"z5",@"z6",@"z7",@"z8"];

        //颜色

        clv.backgroundColor=[UIColor whiteColor];

        imgV.image= [UIImageimageNamed:imgArr[indexPath.row]];

        //添加图片

        [celladdSubview:imgV];

    returncell;

}

还需要第三方一个HWPoTools类.

并且几点在APP.M 添加控制器.

相关文章

网友评论

      本文标题:汽车

      本文链接:https://www.haomeiwen.com/subject/qtmuzftx.html