美文网首页
iOS 模仿饿了吗首页

iOS 模仿饿了吗首页

作者: syh1234 | 来源:发表于2018-05-21 09:53 被阅读0次

    AppDelegate.m


    #import "AppDelegate.h"

    #import "ViewController.h"

    #import "SecondViewController.h"

    #import "ThirdViewController.h"

    #import "FourViewController.h"

    @interface AppDelegate ()

    @end

    @implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        // Override point for customization after application launch.

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

        UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:v1];

        UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"外卖" image:[UIImage imageNamed:@"menu_ico_shop_26x26_@3x"] selectedImage:[UIImage imageNamed:@"menu_ico_shop_on_26x26_@3x"]];

        nav1.tabBarItem = item1;

        SecondViewController *s1 = [[SecondViewController alloc]init];

        UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:s1];

        UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"发现" image:[UIImage imageNamed:@"menu_ico_gather_26x26_@3x"] selectedImage:[UIImage imageNamed:@"menu_ico_gather_on_26x26_@3x"]];

        nav2.tabBarItem = item2;

        ThirdViewController *t1 = [[ThirdViewController alloc]init];

        UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:t1];

        UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"订单" image:[UIImage imageNamed:@"ico_share_wechat_26x26_@3x"] selectedImage:[UIImage imageNamed:@"ico_share_wechat_on_26x26_@3x"]];

        nav3.tabBarItem = item3;

        FourViewController *f1 = [[FourViewController alloc]init];

        UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:f1];

        UITabBarItem *item4 = [[UITabBarItem alloc]initWithTitle:@"我的" image:[UIImage imageNamed:@"menu_ico_center_26x26_@3x"] selectedImage:[UIImage imageNamed:@"menu_ico_center_on_26x26_@3x"]];

        nav4.tabBarItem = item4;

        UITabBarController *tabbar = [[UITabBarController alloc]init];

        tabbar.viewControllers = @[nav1,nav2,nav3,nav4];

        self.window.rootViewController = tabbar;

        return YES;

    }

    - (void)applicationWillResignActive:(UIApplication *)application {

        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

    }

    - (void)applicationDidEnterBackground:(UIApplication *)application {

        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

    }

    - (void)applicationWillEnterForeground:(UIApplication *)application {

        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

    }

    - (void)applicationDidBecomeActive:(UIApplication *)application {

        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    }

    - (void)applicationWillTerminate:(UIApplication *)application {

        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

    }

    @end


    TwoBtn.m


    #import "TwoBtn.h"

    @implementation TwoBtn

    //调整title的位置

    - (CGRect)titleRectForContentRect:(CGRect)contentRect

    {

        CGRect rect;

        CGFloat titleW = contentRect.size.width;

        CGFloat titleH = 20;

        CGFloat titleX = 10;

        CGFloat titleY = 60;

        rect = CGRectMake(titleX, titleY, titleW, titleH);

        return rect;

    }

    //调整image的位置

    - (CGRect)imageRectForContentRect:(CGRect)contentRect

    {

        CGRect rect;

        CGFloat imageW = 50;

        CGFloat imageH = 50;

        CGFloat imageX = 15;

        CGFloat imageY = 0;

        rect = CGRectMake(imageX, imageY, imageW, imageH);

        return rect;

    }

    @end


    MyButton.m


    #import "MyButton.h"

    @implementation MyButton

    //调整title的位置

    - (CGRect)titleRectForContentRect:(CGRect)contentRect

    {

        CGRect rect;

        CGFloat titleW = 100;

        CGFloat titleH = 30;

        CGFloat titleX = 10;

        CGFloat titleY = 15;

        rect = CGRectMake(titleX, titleY, titleW, titleH);

        return rect;

    }

    //调整image的位置

    - (CGRect)imageRectForContentRect:(CGRect)contentRect

    {

        CGRect rect;

        CGFloat imageW = 50;

        CGFloat imageH = 50;

        CGFloat imageX = 130;

        CGFloat imageY = 8;

        rect = CGRectMake(imageX, imageY, imageW, imageH);

        return rect;

    }

    @end


    OneTableViewCell.m


    #import "OneTableViewCell.h"

    @implementation OneTableViewCell

    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

    {

        if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

            [self CustomUi];

        }

        return self;

    }

    - (void)CustomUi

    {

        UIView *views = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 414, 180)];

        views.backgroundColor = [UIColor colorWithRed:27/255.0 green:154/255.0 blue:252/255.0 alpha:1.0];

        [self.contentView addSubview:views];

        UILabel *labels = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, 200, 50)];

        labels.text = @"饿了就要饿了么";

        labels.textColor = [UIColor whiteColor];

        labels.font = [UIFont systemFontOfSize:28 weight:2.0];

        [views addSubview:labels];

        UILabel *labelss = [[UILabel alloc]initWithFrame:CGRectMake(350, 28, 30, 20)];

        labelss.textColor = [UIColor whiteColor];

        labelss.text = @"33°";

        labelss.font = [UIFont systemFontOfSize:13];

        [views addSubview:labelss];

        UILabel *labelsss = [[UILabel alloc]initWithFrame:CGRectMake(358, 41, 20, 20)];

        labelsss.textColor = [UIColor whiteColor];

        labelsss.text = @"阴";

        labelsss.font = [UIFont systemFontOfSize:11];

        [views addSubview:labelsss];

        UILabel *labelssss = [[UILabel alloc]initWithFrame:CGRectMake(380, 26, 40, 40)];

        labelssss.textColor = [UIColor whiteColor];

        labelssss.text = @"☁️";

        labelssss.font = [UIFont systemFontOfSize:15];

        [views addSubview:labelssss];

        UILabel *labelsT = [[UILabel alloc]initWithFrame:CGRectMake(10, 75, 200, 20)];

        labelsT.text = @"❤ 八维研修学院(第二校区) ▼";

        labelsT.textColor = [UIColor whiteColor];

        labelsT.font = [UIFont systemFontOfSize:13];

        [views addSubview:labelsT];

        UITextField *textF = [[UITextField alloc]initWithFrame:CGRectMake(8, 103, 398, 40)];

        textF.text = @"🔍输入商家、商品名称";

        textF.textAlignment = NSTextAlignmentCenter;

        textF.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];

        textF.textColor = [UIColor grayColor];

        textF.font = [UIFont systemFontOfSize:13];

        textF.layer.cornerRadius = 15;

        textF.layer.masksToBounds = YES;

        [views addSubview:textF];

        CGFloat width = 50;

        CGFloat X = 10;

        NSArray *array = [NSArray array];

        array = @[@"西瓜",@"醉唐轩",@"三元",@"加班食补",@"我的菜",@"红烧肉",@"肯德基",@"庆丰"];

        for (int i = 0; i < 8 ; i ++) {

            UILabel *labelTT = [[UILabel alloc]initWithFrame:CGRectMake((X+width)*i, 150, width, 20)];

            labelTT.text = array[i];

            labelTT.textColor = [UIColor whiteColor];

            labelTT.font = [UIFont systemFontOfSize:12];

            [views addSubview:labelTT];

        }

    }

    @end


    TwoTableViewCell.m


    #import "TwoTableViewCell.h"

    #import "MyButton.h"

    #import "TwoBtn.h"

    @implementation TwoTableViewCell

    {

        TwoBtn *btn1;

        TwoBtn *btn2;

        TwoBtn *btn3;

        TwoBtn *btn4;

        TwoBtn *btn5;

        TwoBtn *btn6;

        TwoBtn *btn7;

    }

    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

    {

        if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

            [self setUI];

        }

        return self;

    }

    - (void)setUI

    {

        btn1 = [[TwoBtn alloc]initWithFrame:CGRectMake(15, 10, 60, 60)];

        btn1.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);

        btn1.titleLabel.textAlignment = NSTextAlignmentCenter;

        [btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        btn1.titleLabel.font = [UIFont systemFontOfSize:13];

        [btn1 setTitle:@"汉堡薯条" forState:UIControlStateNormal];

        [btn1 setImage:[UIImage imageNamed:@"Food2"] forState:UIControlStateNormal];

        btn2 = [[TwoBtn alloc]initWithFrame:CGRectMake(115, 10, 60, 60)];

        btn2.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);

        btn2.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);

        btn2.titleLabel.textAlignment = NSTextAlignmentCenter;

        [btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        btn2.titleLabel.font = [UIFont systemFontOfSize:13];

        btn2.titleLabel.textAlignment = NSTextAlignmentCenter;

        [btn2 setTitle:@"包子粥店" forState:UIControlStateNormal];

        [btn2 setImage:[UIImage imageNamed:@"Food3"] forState:UIControlStateNormal];

        btn3 = [[TwoBtn alloc]initWithFrame:CGRectMake(215, 10, 60, 60)];

        btn3.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);

        btn3.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);

        [btn3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        btn3.titleLabel.font = [UIFont systemFontOfSize:13];

        btn3.titleLabel.textAlignment = NSTextAlignmentCenter;

        [btn3 setTitle:@"鲜花蛋糕" forState:UIControlStateNormal];

        [btn3 setImage:[UIImage imageNamed:@"Food4"] forState:UIControlStateNormal];

        btn4 = [[TwoBtn alloc]initWithFrame:CGRectMake(315, 10, 60, 60)];

        btn4.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);

        btn4.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);

        [btn4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        btn4.titleLabel.font = [UIFont systemFontOfSize:13];

        btn4.titleLabel.textAlignment = NSTextAlignmentCenter;

        [btn4 setTitle:@"麻辣烫" forState:UIControlStateNormal];

        [btn4 setImage:[UIImage imageNamed:@"Food5"] forState:UIControlStateNormal];

        btn5 = [[TwoBtn alloc]initWithFrame:CGRectMake(15, 100, 60, 60)];

        btn5.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);

        btn5.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);

        [btn5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        btn5.titleLabel.font = [UIFont systemFontOfSize:13];

        btn5.titleLabel.textAlignment = NSTextAlignmentCenter;

        [btn5 setTitle:@"地方菜" forState:UIControlStateNormal];

        [btn5 setImage:[UIImage imageNamed:@"Food5"] forState:UIControlStateNormal];

        btn6 = [[TwoBtn alloc]initWithFrame:CGRectMake(115, 100, 60, 60)];

        btn6.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);

        btn6.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);

        [btn6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        btn6.titleLabel.font = [UIFont systemFontOfSize:13];

        btn6.titleLabel.textAlignment = NSTextAlignmentCenter;

        [btn6 setTitle:@"披萨意面" forState:UIControlStateNormal];

        [btn6 setImage:[UIImage imageNamed:@"Food5"] forState:UIControlStateNormal];

        btn7 = [[TwoBtn alloc]initWithFrame:CGRectMake(215, 100, 60, 60)];

        btn7.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 50, 10);

        btn7.titleEdgeInsets = UIEdgeInsetsMake(80, 0, 0, 0);

        [btn7 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        btn7.titleLabel.font = [UIFont systemFontOfSize:13];

        btn7.titleLabel.textAlignment = NSTextAlignmentCenter;

        [btn7 setTitle:@"异国料理" forState:UIControlStateNormal];

        [btn7 setImage:[UIImage imageNamed:@"Food5"] forState:UIControlStateNormal];

        [self.contentView addSubview:btn1];

        [self.contentView addSubview:btn2];

        [self.contentView addSubview:btn3];

        [self.contentView addSubview:btn4];

        [self.contentView addSubview:btn5];

        [self.contentView addSubview:btn6];

        [self.contentView addSubview:btn7];

    //    CGFloat width = 60;

    //    CGFloat height = 60;

    //    CGFloat X = 10+width;

    //    NSArray *array = [NSArray array];

    //    array = @[@"汉堡薯条",@"包子粥店",@"鲜花蛋糕",@"麻辣烫"];

    //    NSArray *arrays = [NSArray array];

    //    arrays = @[@"Food1",@"Food2",@"Food3",@"Food4"];

    //    for (int i = 0; i < 4; i ++) {

    //        MyButton *btns =[[MyButton alloc]initWithFrame:CGRectMake(X*i, 20, width, height)];

    //        [btns setImage:[UIImage imageNamed:arrays[i]] forState:UIControlStateNormal];

    //        [btns setTitle:array[i] forState:UIControlStateNormal];

    //        [btns setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    //        btns.titleLabel.font = [UIFont systemFontOfSize:13];

    //        btns.titleLabel.textAlignment = NSTextAlignmentCenter;

    //        [self.contentView addSubview:btns];

    //    }

    }

    @end


    ThreeTableViewCell.m


    #import "ThreeTableViewCell.h"

    @implementation ThreeTableViewCell

    {

        //实现三个属性

        UIScrollView *scroll;

        NSArray *imgArr;//图片

        UIPageControl *page;//页面

    }

    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

    {

        if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

            [self CustomUI];

        }

        return self;

    }

    - (void)CustomUI

    {

        scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(8, 5, 398, 100)];

        [self.contentView addSubview:scroll];

        imgArr = @[@"切片1",@"899724a811384b1c24b081ba456df08f.jpg.png",@"b7d69dc73c527365a8826b0d753aaea7.jpg"];

        //设置图片进行滚动

        scroll.pagingEnabled = YES;

        for (int i = 0; i < imgArr.count; i++)

        {

            UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(398 * i, 0, 398, 100)];

            img.userInteractionEnabled = YES;

            img.image = [UIImage imageNamed:imgArr[i]];

            [scroll addSubview:img];

        }

        scroll.contentSize = CGSizeMake(398 * imgArr.count, 100);

        //取消弹簧效果

        scroll.bounces = NO;

        //隐藏滚动条

        scroll.showsHorizontalScrollIndicator = NO;

        //页码  (点)

        page = [[UIPageControl alloc]initWithFrame:CGRectMake((398 -100) / 2, 80, 100, 20)];

        page.numberOfPages = imgArr.count;

        //设置初始页码

        page.currentPage = 0;

        //设置页码的颜色

        page.pageIndicatorTintColor = [UIColor grayColor];

        [self.contentView addSubview:page];

    //    UIImageView *images = [[UIImageView alloc]initWithFrame:CGRectMake(8, 5, 398, 100)];

    //    images.image = [UIImage imageNamed:@"切片1"];

    //    [self.contentView addSubview:images];

    //

        UIView *views = [[UIView alloc]initWithFrame:CGRectMake(0, 110, 414, 8)];

        views.backgroundColor = [UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1.0];

        [self.contentView addSubview:views];

    }

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView

    {

        NSLog(@"contentOffset: x: %f,y: %f",scrollView.contentOffset.x,scrollView.contentOffset.y);

        //求余

        NSInteger index = scroll.contentOffset.x / scrollView.frame.size.width;

        page.currentPage = index;

    }

    @end


    FourTableViewCell.m


    #import "FourTableViewCell.h"

    #import "MyButton.h"

    @implementation FourTableViewCell

    {

        MyButton *buttom1;

        MyButton *buttom2;

        MyButton *buttom3;

        MyButton *buttom4;

    }

    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

    {

        if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

            [self customUI];

        }

        return self;

    }

    - (void)customUI

    {

        self.backgroundColor = [UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1.0];

        buttom1 = [[MyButton alloc]initWithFrame:CGRectMake(0, 0, 206, 75)];

        buttom1.backgroundColor = [UIColor whiteColor];

        buttom1.titleLabel.textAlignment = NSTextAlignmentCenter;

        [buttom1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        buttom1.titleLabel.font = [UIFont systemFontOfSize:15 weight:2];

        [buttom1 setTitle:@"四星晚餐" forState:UIControlStateNormal];

        [buttom1 setImage:[UIImage imageNamed:@"Food1"] forState:UIControlStateNormal];

        [self.contentView addSubview:buttom1];

        UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(28, 40, 100, 20)];

        label1.text = @"满40减20起";

        label1.textColor = [UIColor lightGrayColor];

        label1.font = [UIFont systemFontOfSize:12];

        [buttom1 addSubview:label1];

        buttom2 = [[MyButton alloc]initWithFrame:CGRectMake(207, 0, 207, 75)];

        buttom2.backgroundColor = [UIColor whiteColor];

        buttom2.titleLabel.textAlignment = NSTextAlignmentCenter;

        [buttom2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        buttom2.titleLabel.font = [UIFont systemFontOfSize:15 weight:2];

        [buttom2 setTitle:@"霸王餐" forState:UIControlStateNormal];

        [buttom2 setImage:[UIImage imageNamed:@"Food2"] forState:UIControlStateNormal];

        [self.contentView addSubview:buttom2];

        UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(35, 40, 100, 20)];

        label2.text = @"领20元红包";

        label2.textColor = [UIColor lightGrayColor];

        label2.font = [UIFont systemFontOfSize:12];

        [buttom2 addSubview:label2];

        buttom3 = [[MyButton alloc]initWithFrame:CGRectMake(0, 76, 206, 75)];

        buttom3.backgroundColor = [UIColor whiteColor];

        buttom3.titleLabel.textAlignment = NSTextAlignmentCenter;

        [buttom3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        buttom3.titleLabel.font = [UIFont systemFontOfSize:15 weight:2];

        [buttom3 setTitle:@"快选加班餐" forState:UIControlStateNormal];

        [buttom3 setImage:[UIImage imageNamed:@"Food3"] forState:UIControlStateNormal];

        [self.contentView addSubview:buttom3];

        UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(28, 40, 100, 20)];

        label3.text = @"低至5折";

        label3.textColor = [UIColor lightGrayColor];

        label3.font = [UIFont systemFontOfSize:12];

        [buttom3 addSubview:label3];

        buttom4 = [[MyButton alloc]initWithFrame:CGRectMake(207, 76, 207, 75)];

        buttom4.backgroundColor = [UIColor whiteColor];

        buttom4.titleLabel.textAlignment = NSTextAlignmentCenter;

        [buttom4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        buttom4.titleLabel.font = [UIFont systemFontOfSize:15 weight:2];

        [buttom4 setTitle:@"立减10元" forState:UIControlStateNormal];

        [buttom4 setImage:[UIImage imageNamed:@"Food4"] forState:UIControlStateNormal];

        [self.contentView addSubview:buttom4];

        UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(35, 40, 100, 20)];

        label4.text = @"周二开胃菜";

        label4.textColor = [UIColor lightGrayColor];

        label4.font = [UIFont systemFontOfSize:12];

        [buttom4 addSubview:label4];

    }

    @end


    ViewController.m


    #import "ViewController.h"#import "OneTableViewCell.h"#import "TwoTableViewCell.h"#import "ThreeTableViewCell.h"#import "FourTableViewCell.h"static NSString *cellid = @"deliciousCell";static NSString *cellids = @"functionCell";static NSString *cellidss = @"menucell";static NSString *contentid = @"contentcell";@interface ViewController ()@property (nonatomic,strong)UITableView *tables;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor = [UIColor whiteColor];

        self.navigationController.navigationBarHidden = YES;

        [self tables];

    }

    - (UITableView *)tables

    {

        if (!_tables) {

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

            _tables.delegate = self;

            _tables.dataSource = self;

            [_tables registerClass:[OneTableViewCell class] forCellReuseIdentifier:cellid];

            [_tables registerClass:[TwoTableViewCell class] forCellReuseIdentifier:cellids];

            [_tables registerClass:[ThreeTableViewCell class] forCellReuseIdentifier:cellidss];

            [_tables registerClass:[FourTableViewCell class] forCellReuseIdentifier:contentid];

            [self.view addSubview:_tables];

        }

        return _tables;

    }

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

    {

        return 4;

    }

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

    {

        return 1;

    }

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

    {

        UITableViewCell *cell;

        switch (indexPath.section)

        {

            case 0:{

                OneTableViewCell *Ocells = [tableView dequeueReusableCellWithIdentifier:cellid];

                if (!Ocells) {

                    Ocells = [[OneTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];

                }

                return Ocells;

            }

                break;

            case 1:{

                TwoTableViewCell *Tcells = [tableView dequeueReusableCellWithIdentifier:cellids];

                if (!Tcells) {

                    Tcells = [[TwoTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellids];

                }

                return Tcells;

            }

                break;

            case 2:{

                ThreeTableViewCell *Ttcells = [tableView dequeueReusableCellWithIdentifier:cellidss];

                if (!Ttcells) {

                    Ttcells = [[ThreeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidss];

                }

                return Ttcells;

            }

                break;

            case 3:

            {

                FourTableViewCell *fcells = [tableView dequeueReusableCellWithIdentifier:contentid];

                if (!fcells) {

                    fcells = [[FourTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:contentid];

                }

                return fcells;

            }

                break;

            default:

            {

                cell = [tableView dequeueReusableCellWithIdentifier:@""];

                if (!cell)

                {

                    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];

                }

            }

                break;

        }

        return cell;

    }

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

    {

        if (indexPath.section == 0) {

            return 180;

        }

        else if (indexPath.section ==1){

            return 180;

        }

        else if (indexPath.section == 2){

            return 119;

        }

        else if (indexPath.section == 3){

            return 158;

        }

        return 0;

    }

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    {

        [_tables deselectRowAtIndexPath:indexPath animated:YES];

    }

    @end


    SecondViewController.m

    ThirdViewController.m

    FourViewController.m


    self.view.backgroundColor = [UIColor whiteColor];


    相关文章

      网友评论

          本文标题:iOS 模仿饿了吗首页

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