麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

[iOSUI進階-2.0]彩票Demov1.0

2019-11-14 19:41:46
字體:
來源:轉載
供稿:網友
A.需求
1.模仿“網易彩票”做出有5個導航頁面和相應功能的Demo
2.v1.0 版本搭建基本框架
 
code source:https://github.com/hellovoidworld/HelloLottery
Image
 
B.搭建基本框架
1.拖入TaBarController,5個NavigationController和對應的5個UIViewController
Image(296)
 
2.配置圖標和啟動畫面
AppIcon直接拖入圖片
LaunchImage在Xcode6中需要先更改啟動圖使用圖庫的圖片,而不是LaunchImage.xib
6A490F17-B44B-454E-B38D-6DA56E05F17E
 
Image(297)
 
Image(298)
 
Image(299)
 
2.引入圖片包
Image(300)
 
4. 按照模塊分類代碼包
Image(301)
 
3.底部導航--自定義TabBar
(1)基本設計
Image(302)
 
a.自定義HVWTabBarController、繼承自UIView的HVWTabBar、繼承UIButton的HVWTabBarButton
Image(303)
 
 
b.在自定義TabBar控制器viewDidLoad,刪除原來的TabBar,加上自定義的TabBar
c.加入自定義的按鈕圖片、選中圖片
d.選中事件,轉換圖片
e.按下馬上激發按鈕激發
重寫TabBarButton的[button setHighlighted:]取消高亮狀態
HVWTabBarButton:
1 // 覆蓋setHighlighted,取消點擊時的高亮狀態2 - (void)setHighlighted:(BOOL)highlighted {3 //    [super setHighlighted:highlighted];4 }
 
初步實現都在HVWTabBarController的viewDidLoad方法中:
 1 - (void)viewDidLoad { 2     [super viewDidLoad]; 3     // Do any additional setup after loading the view. 4     5     // 1.刪除原來的TabBar 6     [self.tabBar removeFromSuperview]; 7     8     // 2.添加自定義TabBar 9     HVWTabBar *hvwTabBar = [[HVWTabBar alloc] init];10     hvwTabBar.frame = self.tabBar.frame;11     hvwTabBar.backgroundColor = [UIColor greenColor]; // 設置綠色底的tabBar,稍后會被按鈕圖片覆蓋12     [self.view addSubview:hvwTabBar];13    14     // 3.添加按鈕15     for (int i=0; i<5; i++) {16         // 3.1創建按鈕17         HVWTabBarButton *button = [HVWTabBarButton buttonWithType:UIButtonTypeCustom];18         button.tag = i;19 20         // 3.2設置按鈕背景圖片21         [button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"TabBar%d", i+1]] forState:UIControlStateNormal];22        23         [button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"TabBar%dSel", i+1]]  forState:UIControlStateSelected];24        25         // 3.3設置frame26         CGFloat buttonWidth = hvwTabBar.frame.size.width / 5;27         CGFloat buttonHeight = hvwTabBar.frame.size.height;28         CGFloat buttonX = i * buttonWidth;29         CGFloat buttonY = 0;30         button.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);31        32         // 3.4添加到tabBar33         [hvwTabBar addSubview:button];34        35         // 3.5添加監聽事件36         [button addTarget:self action:@selector(tabBarButtonClicked:) forControlEvents:UIControlEventTouchUpInside];37        38         // 3.6默認已經點擊了第一個按鈕39         if (i == 0) {40             [self tabBarButtonClicked:button];41         }42     }43 }44 45 - (void) tabBarButtonClicked:(HVWTabBarButton *) button {46     // 1.取消選中之前的按鈕47     self.selectedButton.selected = NO;48    49     // 2.選中新點擊的按鈕50     button.selected = YES;51    52     // 3.設置為當前選中的按鈕53     self.selectedButton = button;54    55     // 4.切換子控制器56     self.selectedIndex = button.tag;57 }

 

 
Image(304)
 
 
(2)封裝TabBar代碼
Image(305)
a.重寫initWithFrame:創建初始化TabBar
b.移動子控件的初始化代碼到layoutSubviews
c.通過代理轉換Navigation頁面
d.封裝添加按鈕函數
 1 // 2 //  HWTabBarController.m 3 //  HelloLottery 4 // 5 //  Created by hellovoidworld on 14/12/31. 6 //  Copyright (c) 2014年 hellovoidworld. All rights reserved. 7 // 8  9 #import "HvWTabBarController.h"10 #import "HVWTabBar.h"11 #import "HVWTabBarButton.h"12 13 @interface HVWTabBarController () <HVWTabBarDelegate>14 15 @end16 17 @implementation HVWTabBarController18 19 - (void)viewDidLoad {20     [super viewDidLoad];21     // Do any additional setup after loading the view.22    23     // 1.刪除原來的TabBar24     [self.tabBar removeFromSuperview];25    26     // 2.添加自定義TabBar27     HVWTabBar *hvwTabBar = [[HVWTabBar alloc] init];28     hvwTabBar.frame = self.tabBar.frame;29     hvwTabBar.backgroundColor = [UIColor greenColor]; // 設置綠色底的tabBar,稍后會被按鈕圖片覆蓋30     hvwTabBar.delegate = self;31     [self.view addSubview:hvwTabBar];32 }33 34 - (void)didReceiveMemoryWarning {35     [super didReceiveMemoryWarning];36     // Dispose of any resources that can be recreated.37 }38 39 #PRagma mark - HVWTabBarDelegate 代理方法40 - (void)hvwTabBar:(HVWTabBar *)hvwTabBar didClickedButtonFrom:(int)from to:(int)to {41     // 切換子控制器42     self.selectedIndex = to;43 }44 45 @end
 
 1 // 2 //  HVWTabBar.h 3 //  HelloLottery 4 // 5 //  Created by hellovoidworld on 14/12/31. 6 //  Copyright (c) 2014年 hellovoidworld. All rights reserved. 7 // 8  9 #import <UIKit/UIKit.h>10 11 @class HVWTabBar;12 13 /** 代理協議 */14 @protocol HVWTabBarDelegate <NSObject>15 @optional16 - (void) hvwTabBar:(HVWTabBar *) hvwTabBar didClickedButtonFrom:(int) from to:(int) to;17 @end18 19 @interface HVWTabBar : UIView20 21 /** 代理 */22 @property(nonatomic, weak) id<HVWTabBarDelegate> delegate;23 24 @end

 

 1 // 2 //  HVWTabBar.m 3 //  HelloLottery 4 // 5 //  Created by hellovoidworld on 14/12/31. 6 //  Copyright (c) 2014年 hellovoidworld. All rights reserved. 7 // 8  9 #import "HVWTabBar.h"10 #import "HVWTabBarButton.h"11 12 #define HVWTabBarButtonCount 513 14 @interface HVWTabBar()15 16 @property(nonatomic, weak) HVWTabBarButton *selectedButton;17 18 @end19 20 @implementation HVWTabBar21 22 // 重寫initWithFrame方法,添加tabBar按鈕23 - (instancetype)initWithFrame:(CGRect)frame {24     if (self = [super initWithFrame:frame]) {25         [self initButtons];26     }27    28     return self;29 }30 31 /** 初始化按鈕 */32 - (void) initButtons {33     for (int i=0; i<HVWTabBarButtonCount; i++) {34         // 3.1創建按鈕35         HVWTabBarButton *button = [HVWTabBarButton buttonWithType:UIButtonTypeCustom];36         button.tag = i;37        38         // 3.2設置按鈕背景圖片39         [button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"TabBar%d", i+1]] forState:UIControlStateNormal];40        41         [button setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"TabBar%dSel", i+1]]  forState:UIControlStateSelected];42        43         // 3.3添加到tabBar44         [self addSubview:button];45        46         // 3.4添加監聽事件47         [button addTarget:self action:@selector(tabBarButtonClicked:) forControlEvents:UIControlEventTouchUpInside];48        49         // 3.5默認已經點擊了第一個按鈕50         if (i == 0) {51             [self tabBarButtonClicked:button];52         }53     }54 }55 56 /** 初始化子控件的位置尺寸 */57 - (void)layoutSubviews {58     [super layoutSubviews];59    60     for (int i=0; i<HVWTabBarButtonCount; i++) {61         HVWTabBarButton *button = self.subviews[i];62         CGFloat buttonWidth = self.frame.size.width / 5;63         CGFloat buttonHeight = self.frame.size.height;64         CGFloat buttonX = i * buttonWidth;65         CGFloat buttonY = 0;66         button.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);67     }68 }69 70 - (void) tabBarButtonClicked:(HVWTabBarButton *) button {71     // 1.調用代理方法,通知TabBarController切換子控制器72     if ([self.delegate respondsToSelector:@selector(hvwTabBar:didClickedButtonFrom:to:)]) {73         [self.delegate hvwTabBar:self didClickedButtonFrom:self.selectedButton.tag to:button.tag];74     }75    76     // 2.取消選中之前的按鈕77     self.selectedButton.selected = NO;78    79     // 3.選中新點擊的按鈕80     button.selected = YES;81    82     // 4.設置為當前選中的按鈕83     self.selectedButton = button;84 }85 86 @end
 
4.頭部Navigation導航欄主題設置
Image(306)
 
Image(307)
 
(1)讓applicatoin管理狀態欄
(2)Navigation導航欄背景圖片
(3)統一設置所有Navigation導航欄
[UINavigationBar appearance]; // 所有Navigation導航欄(頭部導航欄)
(4)設置所有Navigation導航欄字體顏色
(5)根據系統版本,設置Navigation導航欄背景圖片
 
(6)在二級頁面隱藏底部導航條,重寫導航控制器的push方法
a.自定義一個導航控制器HVWNavigationController類,重寫push,隱藏底部導航欄
b.設置為每個NavigationController的class
c.導航控制器類的initialize只會在類第一次使用的時候調用一次
所以,導航欄的主題設置可以放在initialize方法中
 
解決:
(1)使用application管理狀態欄
設置不使用控制器控制狀態欄
Image(308)
 
在AppDelegate中設置:
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {2     // Override point for customization after application launch.3    4     // 設置狀態欄樣式為白色5     application.statusBarStyle = UIStatusBarStyleLightContent;6    7     return YES;8 }
 
(2)創建自定義NavigationController類,并設置5個Navigation控制器的class為此類
Image(309)
 
 
(3)不要刪除原來的tabBar,而是覆蓋它,才能控制push事件中底部導航欄
HVWTabBarController:
 1 - (void)viewDidLoad { 2     [super viewDidLoad]; 3     // Do any additional setup after loading the view. 4     5     // 1.添加自定義TabBar 6     HVWTabBar *hvwTabBar = [[HVWTabBar alloc] init]; 7     hvwTabBar.frame = self.tabBar.bounds; 8     hvwTabBar.delegate = self; 9    10     // 2.設置tabBar11     [self.tabBar addSubview:hvwTabBar];12 }
 
(4)在NavigationController中編寫類初始化方法和重寫push方法
 1 // 2 //  HVWNavigationController.m 3 //  HelloLottery 4 // 5 //  Created by hellovoidworld on 15/1/1. 6 //  Copyright (c) 2015年 hellovoidworld. All rights reserved. 7 // 8  9 #import "HVWNavigationController.h"10 11 12 @interface HVWNavigationController ()13 14 @end15 16 @implementation HVWNavigationController17 18 - (void)viewDidLoad {19     [super viewDidLoad];20     // Do any additional setup after loading the view.21    22 }23 24 - (void)didReceiveMemoryWarning {25     [super didReceiveMemoryWarning];26     // Dispose of any resources that can be recreated.27 }28 29 /** 類初始化方法,僅調用一次 */30 + (void) initialize {31     // 獲取能夠控制所有NavigationBar的實例32     UINavigationBar *navBar = [UINavigationBar appearance];33    34     // 設置背景圖片35     NSString *bgImageName;36     if (iOS7) { // 在HelloLottery-Prefix.pch中定義了判斷iOS版本的全局變量37         bgImageName = @"NavBar64";38     } else {39         bgImageName = @"NavBar";40     }41    42     [navBar setBackgroundImage:[UIImage imageNamed:bgImageName] forBarMetrics:UIBarMetricsDefault];43    44     // 設置文本45     NSMutableDictionary *attr = [NSMutableDictionary dictionary];46     attr[NSForegroundColorAttributeName] = [UIColor whiteColor];47     attr[NSFontAttributeName] = [UIFont systemFontOfSize:16];48     [navBar setTitleTextAttributes:attr];49 }50 51 // 攔截所有的push操作52 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {53     viewController.hidesBottomBarWhenPushed = YES; // 這是原來NavigationController中的tabBar,所以要設置自定義的tabBar為Navigation中的tabBar54     [super pushViewController:viewController animated:YES];55 }56 57 @end58  
 
 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成人污在线 | teensexhd | 92看片淫黄大片欧美看国产片 | 午夜在线观看视频网站 | 激情小说激情电影 | 成人勉费视频 | 欧美一级高潮 | 狠狠久久伊人中文字幕 | 久久免费综合视频 | 中国av免费观看 | 亚洲人成中文字幕在线观看 | 欧美成人精品欧美一级 | 成人福利在线视频 | 91短视频在线观看 | 国产精品美女久久久久久网站 | 国产又粗又爽又深的免费视频 | av电影免费观看 | 久久国精品| arabxxxxvideos| 亚洲欧美aⅴ| 久久综合一区二区 | 蜜桃久久一区二区三区 | 亚洲国产成人一区 | 成人一区二区在线观看视频 | 激情夜色| 人人做人人看 | 202z中文字幕第一页 | 欧美老逼 | 国产精品看片 | 毛片视频网址 | 欧美一级高潮 | 蜜桃视频在线观看视频 | 国产99一区二区 | a视频在线免费观看 | 色婷婷av一区二区三区久久 | 精品国产专区 | 日本在线视频二区 | 一本色道久久99精品综合蜜臀 | jizzzxxxxhd | 欧美精品电影一区二区 | 韩国精品视频在线观看 |