iOS 模仿餓了嗎首頁

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:@"發(fā)現(xiàn)" 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

//調(diào)整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;

}

//調(diào)整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

//調(diào)整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;

}

//調(diào)整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 = @"? 八維研修學(xué)院(第二校區(qū)) ▼";

? ? 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 = @[@"西瓜",@"醉唐軒",@"三元",@"加班食補(bǔ)",@"我的菜",@"紅燒肉",@"肯德基",@"慶豐"];

? ? 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:@"漢堡薯?xiàng)l" 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 = @[@"漢堡薯?xiàng)l",@"包子粥店",@"鮮花蛋糕",@"麻辣燙"];

//? ? 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

{

? ? //實(shí)現(xiàn)三個(gè)屬性

? ? 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"];

? ? //設(shè)置圖片進(jìn)行滾動(dòng)

? ? 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;

? ? //隱藏滾動(dòng)條

? ? scroll.showsHorizontalScrollIndicator = NO;

? ? //頁碼? (點(diǎn))

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

? ? page.numberOfPages = imgArr.count;

? ? //設(shè)置初始頁碼

? ? page.currentPage = 0;

? ? //設(shè)置頁碼的顏色

? ? 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 = @"領(lǐng)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];


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末边锁,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌饼灿,老刑警劉巖者冤,帶你破解...
    沈念sama閱讀 222,252評(píng)論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件梳毙,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡奥此,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,886評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門惕虑,熙熙樓的掌柜王于貴愁眉苦臉地迎上來窑业,“玉大人奸柬,你說我怎么就攤上這事〈乐眨” “怎么了序攘?”我有些...
    開封第一講書人閱讀 168,814評(píng)論 0 361
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)寻拂。 經(jīng)常有香客問我程奠,道長(zhǎng),這世上最難降的妖魔是什么祭钉? 我笑而不...
    開封第一講書人閱讀 59,869評(píng)論 1 299
  • 正文 為了忘掉前任瞄沙,我火速辦了婚禮,結(jié)果婚禮上慌核,老公的妹妹穿的比我還像新娘距境。我一直安慰自己,他們只是感情好垮卓,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,888評(píng)論 6 398
  • 文/花漫 我一把揭開白布垫桂。 她就那樣靜靜地躺著,像睡著了一般粟按。 火紅的嫁衣襯著肌膚如雪伪货。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,475評(píng)論 1 312
  • 那天钾怔,我揣著相機(jī)與錄音碱呼,去河邊找鬼。 笑死宗侦,一個(gè)胖子當(dāng)著我的面吹牛愚臀,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播矾利,決...
    沈念sama閱讀 41,010評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼姑裂,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了男旗?” 一聲冷哼從身側(cè)響起舶斧,我...
    開封第一講書人閱讀 39,924評(píng)論 0 277
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎察皇,沒想到半個(gè)月后茴厉,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,469評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡什荣,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,552評(píng)論 3 342
  • 正文 我和宋清朗相戀三年矾缓,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片稻爬。...
    茶點(diǎn)故事閱讀 40,680評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡嗜闻,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出桅锄,到底是詐尸還是另有隱情琉雳,我是刑警寧澤样眠,帶...
    沈念sama閱讀 36,362評(píng)論 5 351
  • 正文 年R本政府宣布,位于F島的核電站翠肘,受9級(jí)特大地震影響吹缔,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜锯茄,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,037評(píng)論 3 335
  • 文/蒙蒙 一厢塘、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧肌幽,春花似錦晚碾、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,519評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至廊移,卻和暖如春糕簿,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背狡孔。 一陣腳步聲響...
    開封第一講書人閱讀 33,621評(píng)論 1 274
  • 我被黑心中介騙來泰國打工懂诗, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人苗膝。 一個(gè)月前我還...
    沈念sama閱讀 49,099評(píng)論 3 378
  • 正文 我出身青樓殃恒,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國和親辱揭。 傳聞我的和親對(duì)象是個(gè)殘疾皇子离唐,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,691評(píng)論 2 361

推薦閱讀更多精彩內(nèi)容