標簽控制器簡單搭建

// AppDelegate.m

#import "ViewController.h"

#import "LViewController.h"


//啟動圖在屏幕顯示時間

sleep(0);

//判斷是不是第一次打開 如果不是就不顯示

//判斷是否是第一次不是就沒有啟動動畫

BOOL show=[[NSUserDefaults standardUserDefaults] objectForKey:@"show"];

if(show==NO)

{

[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"show"];

LViewController *st=[LViewController new];

self.window.rootViewController=st;

}

else

{

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

self.window.rootViewController = vc;

}


// ViewController.m

#import "oneViewController.h"

#import "twoViewController.h"

#import "threeViewController.h"

#import "myKuaiViewController.h"


oneViewController *one = [[oneViewController alloc]init];

twoViewController *fenLei = [[twoViewController alloc] init];

threeViewController *gouWuChe = [[threeViewController alloc]init];

myKuaiViewController *myKuaiF = [[myKuaiViewController alloc]init];

UINavigationController *navo = [[UINavigationController alloc]initWithRootViewController:one];

UINavigationController *navf = [[UINavigationController alloc]initWithRootViewController:fenLei];

UINavigationController *navg = [[UINavigationController alloc]initWithRootViewController:gouWuChe];

UINavigationController *navm = [[UINavigationController alloc]initWithRootViewController:myKuaiF];

myKuaiF.tabBarItem.image = [UIImage imageNamed:@"2"];

myKuaiF.title = @"我的快方";

UITabBarItem *item1 = [[UITabBarItem alloc]initWithTitle:@"首頁" image:[UIImage imageNamed:@"2.png"] tag:1];

UITabBarItem *item2 = [[UITabBarItem alloc]initWithTitle:@"分類" image:[UIImage imageNamed:@"2.png"] tag:1];

UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"購物車" image:[UIImage imageNamed:@"2"] tag:1];

//? ? UITabBarItem *item4 = [[UITabBarItem alloc]initWithTitle:@"我的快方" image:[UIImage imageNamed:@"4.png"] tag:1];

navo.tabBarItem = item1;

navf.tabBarItem = item2;

navg.tabBarItem = item3;

//? ? navm.tabBarItem = item4;

self.viewControllers = @[navo,navf,navg,myKuaiF];


//輪播圖// LViewController.m

#import "oneViewController.h"

#import "ViewController.h"

{

//創(chuàng)建滑動控件

UIScrollView *theScroll;

//分頁控件

UIPageControl *thePage;

//創(chuàng)建整型類

NSInteger tegPageTime;

//創(chuàng)建數(shù)組;

NSArray *theArray;

//計數(shù)器

NSTimer *theTime;

}


//=============================

//獲取屏幕的寬

float width = self.view.frame.size.width;

//獲取屏幕的高

float height = self.view.frame.size.height;

//代替 初始化滾動控件

theScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, width, height)];

//獲取屏幕X軸

float X = 0.0;

//一共四張圖片

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

{

//圖片初始化

UIImageView *theImg = [[UIImageView alloc] initWithFrame:CGRectMake(X, 0, width, height)];

//將圖片添加到視圖里

theArray = @[[UIImage imageNamed:@"2"],[UIImage imageNamed:@"2"],[UIImage imageNamed:@"2"],[UIImage imageNamed:@"2"],];

//將圖片與數(shù)組下標綁定

theImg.image = theArray[i];

//將圖片添加到滾動視圖中

[theScroll addSubview:theImg];

//設(shè)置滾動視圖的坐標 原代碼

//(width=self.view.frame.size.width+self.view.frame.size.width+self.view.frame.size.width+self.view.frame.size.width,)

X += width;

}

//設(shè)置滾動視圖的大小

theScroll.contentSize = CGSizeMake(width * 4, height);

// 設(shè)置滾動視圖按頁滾動

theScroll.pagingEnabled = YES;

//滾動條隱藏

theScroll.showsHorizontalScrollIndicator = NO;

//設(shè)置代理

theScroll.delegate = self;

//初始化頁碼

thePage = [[UIPageControl alloc]initWithFrame:CGRectMake(width /2-50, 570, 100, 30)];

//頁數(shù)

thePage.numberOfPages = 4;

//初始頁第一頁

thePage.currentPage = 0;

//清除原來顏色

thePage.backgroundColor = [UIColor clearColor];

//沒動原來

thePage.pageIndicatorTintColor = [UIColor greenColor];

//當前翻頁顯示的顏色

thePage.currentPageIndicatorTintColor = [UIColor redColor];

//順序不能亂

[self.view addSubview:theScroll];

[self.view addSubview:thePage];

//記錄當前圖片

tegPageTime = thePage.currentPage;

//第一個幾秒鐘換一下 事件

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

/////==================================

//事件

-(void)scroll

{

tegPageTime ++;

if (tegPageTime>=theArray.count)

{

tegPageTime = 0;

}

[theScroll setContentOffset:CGPointMake(tegPageTime*theScroll.frame.size.width, 0) animated:YES];

}

//表示在滑動滾動視圖的時候調(diào)用此方法

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

CGPoint point=scrollView.contentOffset;//偏移

//獲得所在位置

thePage.currentPage=point.x / scrollView.frame.size.width;

UIButton *theBtn = [[UIButton alloc]init];

if (thePage.currentPage == 3)

{

//停止圖片滾動

[theTime setFireDate:[NSDate distantFuture]];

theBtn.frame = CGRectMake(133, 653, 150, 50);

theBtn.backgroundColor = [UIColor orangeColor];

theBtn.layer.cornerRadius = 26;

[theBtn setTitle:@"立即登錄" forState:UIControlStateNormal];

//添加按鈕觸發(fā)事件:必須要用(UIControlEventTouchUpInside)

[theBtn addTarget:self action:@selector(TiaoZh) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:theBtn];

//設(shè)置與用戶無法交互(這樣即可解決按鈕在前面的那頁中顯示)

//? scrollView.userInteractionEnabled = NO;

}

}

//實現(xiàn)頁碼和滾動視圖的關(guān)聯(lián)

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollVie

{

thePage.currentPage = theScroll.contentOffset.x / self.view.frame.size.width;

}

//跳轉(zhuǎn)

-(void)TiaoZh

{

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

[self presentViewController:VC animated:YES completion:nil];

}


// myKuaiViewController.m

{

//cell每一行標題

NSArray *_array, *_arrayOne,*_arraytwo,*_arraythree,*_arrayfour,*_arrayfive;

UIButton *buttonmoney,*BtnMy;

//橫排cell 按鈕

UIButton *buttonone,*buttontwo,*buttonthree,*buttonfour;

//按鈕 登錄 優(yōu)惠 積分

UIButton *BtnLoaing,*BtnYou,*BtnJi;

UILabel *lableoneDetext,*labletwoDetext,*lablethreeDetext,*lablefourDetext;

}

@property(nonatomic,strong)UITableView *table;


//=============================

self.title = @"我的快方";

self.view.backgroundColor = [UIColor whiteColor];

_arrayOne= @[@"我的訂單"];

_arraytwo = @[@"地址管理",@"瀏覽記錄",@"查看評價"];

_arraythree = @[@"配送范圍",@"推薦有禮",@"積分商城",@"24小時客服電話"];

_arrayfour = @[@"設(shè)置"];

_table = [[UITableView alloc]initWithFrame:CGRectMake(0, -8, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];

_table.delegate = self;

_table.dataSource = self;

//添加視圖

[self.view addSubview:_table];

=========================

//每行cell高度

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

{

if(indexPath.section == 0)

{

if (indexPath.row == 0)

{

return 160;

}

}

else if (indexPath.section == 1)

{

return 53;

}

return 53;

}

//表格每個分區(qū)

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

if(section == 0)

{

//返回的是最上邊的登錄

return 10;

}

else if (section == 1)

{

return 0.01;

}else if (section == 2)

{

return 0.01;

}else if (section == 3)

{

return 0.01;

}

return 21;

}

//一共有幾個分區(qū)

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 4;

}

//每個分區(qū)返回的行數(shù)

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

{

if (section ==0)

{

return 3;

}else if (section == 1)

{

return _arraytwo.count;

}else if (section == 2)

{

return _arraythree.count;

}else if (section == 3)

{

return _arrayfour.count;

}

return _array.count;

}

//cell里的數(shù)據(jù)

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

{

static NSString *string = @"string";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:string];

if (!cell)

{

cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:string];

}

//第一個分區(qū)

if (indexPath.section== 0)

{

if (indexPath.row == 0)

{

UIView *ViewH = [[UIView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width, 160)];

ViewH.backgroundColor = [UIColor redColor];

[cell.contentView addSubview:ViewH];

//點擊某一行不變顏色

cell.selectionStyle = UITableViewCellSelectionStyleNone;

//登錄按鈕

BtnLoaing = [UIButton buttonWithType:UIButtonTypeCustom];

BtnLoaing.frame = CGRectMake(15, 55, 130, 50);

[BtnLoaing setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateNormal];

[BtnLoaing addTarget:self action:@selector(Denglu) forControlEvents:UIControlEventTouchUpInside];

[ViewH addSubview:BtnLoaing];

//優(yōu)惠

BtnYou = [UIButton buttonWithType:UIButtonTypeCustom];

BtnYou.frame = CGRectMake(15, 115, 50, 20);

[BtnYou setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateNormal];

[BtnYou addTarget:self action:@selector(YouHui) forControlEvents:UIControlEventTouchUpInside];

[ViewH addSubview:BtnYou];

UILabel *la = [[UILabel alloc] initWithFrame:CGRectMake(128, 120, 8,14)];

la.text = @"|";

la.textColor = [UIColor whiteColor];

[ViewH addSubview:la];

//積分

BtnJi = [UIButton buttonWithType:UIButtonTypeCustom];

BtnJi.frame = CGRectMake(195, 115, 50, 20);

[BtnJi setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateNormal];

[BtnJi addTarget:self action:@selector(JiFen) forControlEvents:UIControlEventTouchUpInside];

[ViewH addSubview:BtnJi];

}

//我的訂單

else if (indexPath.row == 1)

{

cell.textLabel.text = @"我的訂單";

}

//橫排各種訂單

else if (indexPath.row == 2)

{

//? ? ? ? ? ? cell.textLabel.text = _arrayOne[indexPath.row];

//? ? ? ? ? ? cell.imageView.image = [UIImage imageNamed:@"分類.png"];

//當前訂單

buttonone = [[UIButton alloc]initWithFrame:CGRectMake(-15, 0, self.view.frame.size.width/3, 35)];

[buttonone setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateNormal];

[buttonone setTitleColor:[UIColor colorWithRed:0.61f green:0.36f blue:0.01f alpha:1.0f]forState:UIControlStateNormal];? //正常情況

[buttonone addTarget:self action:@selector(current) forControlEvents:UIControlEventTouchUpInside];

buttonone.adjustsImageWhenHighlighted = YES;

lableoneDetext = [[UILabel alloc]initWithFrame:CGRectMake(-15, 35, self.view.frame.size.width/3, 10)];

lableoneDetext.text = @"當前訂單";

lableoneDetext.textAlignment =? 1;

lableoneDetext.font = [UIFont systemFontOfSize:10];

[cell addSubview:buttonone];

[cell addSubview:lableoneDetext];

//待付款訂單

buttontwo = [[UIButton alloc]initWithFrame:CGRectMake(85, 0, self.view.frame.size.width/3, 35)];

[buttontwo setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateNormal];

[buttontwo setTitleColor:[UIColor colorWithRed:0.61f green:0.36f blue:0.01f alpha:1.0f]forState:UIControlStateNormal];? //正常情況

[buttontwo addTarget:self action:@selector(pending) forControlEvents:UIControlEventTouchUpInside];

buttontwo.adjustsImageWhenHighlighted = YES;

labletwoDetext = [[UILabel alloc]initWithFrame:CGRectMake(85, 35, self.view.frame.size.width/3, 10)];

labletwoDetext.text = @"待付款訂單";

labletwoDetext.textAlignment =? 1;

labletwoDetext.font = [UIFont systemFontOfSize:10];

[cell addSubview:buttontwo];

[cell addSubview:labletwoDetext];

//已完成訂單

buttonthree = [[UIButton alloc]initWithFrame:CGRectMake(185, 0, self.view.frame.size.width/3, 35)];

[buttonthree setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateNormal];

[buttonthree setTitleColor:[UIColor colorWithRed:0.61f green:0.36f blue:0.01f alpha:1.0f]forState:UIControlStateNormal];? //正常情況

[buttonthree addTarget:self action:@selector(over) forControlEvents:UIControlEventTouchUpInside];

buttonthree.adjustsImageWhenHighlighted = YES;

lablethreeDetext = [[UILabel alloc]initWithFrame:CGRectMake(185, 35, self.view.frame.size.width/3, 10)];

lablethreeDetext.text = @"已完成訂單";

lablethreeDetext.textAlignment =? 1;

lablethreeDetext.font = [UIFont systemFontOfSize:10];

[cell addSubview:buttonthree];

[cell addSubview:lablethreeDetext];

//待評價訂單

buttonfour = [[UIButton alloc]initWithFrame:CGRectMake(275, 0, self.view.frame.size.width/3, 35)];

[buttonfour setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateNormal];

[buttonfour setTitleColor:[UIColor colorWithRed:0.61f green:0.36f blue:0.01f alpha:1.0f]forState:UIControlStateNormal];? //正常情況

[buttonfour addTarget:self action:@selector(evaluate) forControlEvents:UIControlEventTouchUpInside];

buttonfour.adjustsImageWhenHighlighted = YES;

lablefourDetext = [[UILabel alloc]initWithFrame:CGRectMake(275, 35, self.view.frame.size.width/3, 10)];

lablefourDetext.text = @"待評價訂單";

lablefourDetext.textAlignment =? 1;

lablefourDetext.font = [UIFont systemFontOfSize:10];

[cell addSubview:buttonfour];

[cell addSubview:lablefourDetext];

}

}

//第二個分區(qū)

else if (indexPath.section ==1)

{

cell.textLabel.text = _arraytwo[indexPath.row];

if (indexPath.row == 0)

{

cell.imageView.image = [UIImage imageNamed:@"2.png"];

}

else if (indexPath.row == 1)

{

cell.imageView.image = [UIImage imageNamed:@"2.png"];

}

else if (indexPath.row == 2)

{

cell.imageView.image = [UIImage imageNamed:@"2.png"];

}

}

//第三個分區(qū)

else

if (indexPath.section ==2)

{

cell.textLabel.text = _arraythree[indexPath.row];

cell.imageView.image = [UIImage imageNamed:@"2.png"];

}

else

if (indexPath.section ==3)

{

if (indexPath.row == 0)

{

}

cell.textLabel.text = _arrayfour[indexPath.row];

cell.imageView.image = [UIImage imageNamed:@"2.png"];

}

//點擊每行后的背景顏色

cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];

cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:236/255.0 green:236/255.0 blue:236/255.0 alpha:0.5];

return cell;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容