国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

[iOSUI進(jìn)階-2.1]彩票Demov1.1

2019-11-14 19:41:25
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
A.需求
1.優(yōu)化項(xiàng)目設(shè)置
2.自定義導(dǎo)航欄標(biāo)題按鈕
3.多版本處理
4.iOS6和iOS7的適配
5.設(shè)置按鈕背景
6.設(shè)置值UIBarButtonItem樣式
 
code source: https://github.com/hellovoidworld/HelloLottery
 
B.實(shí)現(xiàn)
1.項(xiàng)目配置
(1)程序啟動(dòng)期間隱藏狀態(tài)欄
Image
 
(2)程序啟動(dòng)完成顯示狀態(tài)欄
AppDelegate:
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {2     // Override point for customization after application launch.3    4     // 設(shè)置狀態(tài)欄樣式為白色5     application.statusBarHidden = NO;6     application.statusBarStyle = UIStatusBarStyleLightContent;7    8     return YES;9 }
 
(3)取消渲染app圖標(biāo)(取消系統(tǒng)渲染效果)
Image(1)
 
 
2.自定義導(dǎo)航欄標(biāo)題按鈕
“購(gòu)彩大廳”右上角的“咨詢”按鈕是圖標(biāo)+文字型的
Image(2)
 
 
(1)UIBarButtonItem在storyboard中只能選擇文字或者圖片之一(注意NavigationBar內(nèi)只能放UIBarButtonItem)
Image(3)
 
(2)UIBarButtonItem可以包含其他控件,這里我們使用UIButton
Image(4)
 
(3)設(shè)置寬度、內(nèi)間距
Image(5)
 
 
 
3.“合買(mǎi)跟單”導(dǎo)航欄主題點(diǎn)擊下拉菜單
 
 
(1)使用UIButton作為title item
Image(6)
 
(2)自定義UIButton,交換按鈕title和image的位置,實(shí)現(xiàn)titleRectForContentRect和imageRectForContentRect,控制內(nèi)部控件的frame
 1 // 2 //  TitleExtendButton.m 3 //  HelloLottery 4 // 5 //  Created by hellovoidworld on 15/1/3. 6 //  Copyright (c) 2015年 hellovoidworld. All rights reserved. 7 // 8  9 #import "TitleExtendButton.h"10 11 @interface TitleExtendButton()12 13 @PRoperty(nonatomic, strong) UIFont *titleFont;14 15 @end16 17 @implementation TitleExtendButton18 19 /** 從文件加載對(duì)象就會(huì)調(diào)用此方法,例如xib和storybard */20 - (id)initWithCoder:(NSCoder *)aDecoder {21     NSLog(@"從文件加載TitleButton");22     if (self = [super initWithCoder:aDecoder]) {23         [self initializeButton];24     }25 26     return self;27 }28 29 /** 從代碼中加載對(duì)象就會(huì)調(diào)用此方法 */30 - (instancetype)initWithFrame:(CGRect)frame {31     NSLog(@"從代碼加載TitleButton");32     if (self = [super initWithFrame:frame]) {33         [self initializeButton];34     }35    36     return self;37 }38 39 - (void) initializeButton {40     // 設(shè)置font41     self.titleFont = [UIFont systemFontOfSize:14]; // 暫時(shí)先自定義font42     self.titleLabel.font = self.titleFont;43    44     // 圖標(biāo)居中45     [self.imageView setContentMode:UIViewContentModeCenter];46 }47 48 49 /** 返回title的frame */50 - (CGRect)titleRectForContentRect:(CGRect)contentRect {51     CGFloat titleX = 0;52     CGFloat titleY = 0;53    54     NSDictionary *attr = @{NSFontAttributeName : self.titleFont};55     CGFloat titleWidth;56    57     // 只有 iOS7 版本以上才能運(yùn)行以下代碼58     if (iOS7) {59         // 只有 Xcode5 或以上版本才能識(shí)別這段代碼60 #ifdef __ipHONE_7_061     titleWidth = [self.currentTitle boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil].size.width;62 #else63         titleWidth = [self.currentTitle sizeWithFont:self.titleFont].width;64 #endif65     } else { // 否則使用舊的API66         titleWidth = [self.currentTitle sizeWithFont:self.titleFont].width;67     }68    69     CGFloat titleHeight = contentRect.size.height;70    71     return CGRectMake(titleX, titleY, titleWidth, titleHeight);72 }73 74 /** 返回image的frame */75 - (CGRect)imageRectForContentRect:(CGRect)contentRect {76     CGFloat imageWidth = 30;77     CGFloat imageHeight = contentRect.size.height;78     CGFloat imageX = contentRect.size.width - imageWidth;79     CGFloat imageY = 0;80     return CGRectMake(imageX, imageY, imageWidth, imageHeight);81 }82 83 @end
 
Image(7)
 
(3)自定義一個(gè)集成UIViewController的類,設(shè)置為該頁(yè)面的控制器類,拖線監(jiān)聽(tīng)title item點(diǎn)擊事件
a.按鈕效果(“三角形”下拉效果旋轉(zhuǎn))
Image(8)
 
 
Image(9)
 
b.創(chuàng)建一個(gè)UIView,點(diǎn)擊下拉顯示,再次點(diǎn)擊隱藏
 1 // 2 //  HVWBuyViewController.m 3 //  HelloLottery 4 // 5 //  Created by hellovoidworld on 15/1/3. 6 //  Copyright (c) 2015年 hellovoidworld. All rights reserved. 7 // 8  9 #import "HVWBuyViewController.h"10 #import "TitleExtendButton.h"11 12 @interface HVWBuyViewController ()13 14 @property(nonatomic, weak) UIView *popupView;15 16 /** 標(biāo)題點(diǎn)擊事件 */17 - (IBAction)titleClicked:(TitleExtendButton *)sender;18 19 @end20 21 @implementation HVWBuyViewController22 23 - (void)viewDidLoad {24     [super viewDidLoad];25     // Do any additional setup after loading the view.26    27 }28 29 - (void)didReceiveMemoryWarning {30     [super didReceiveMemoryWarning];31     // Dispose of any resources that can be recreated.32 }33 34 /** 延遲初始化彈出view35 * (發(fā)現(xiàn)放在viewDidLoad的時(shí)候,在點(diǎn)擊按鈕調(diào)用的時(shí)候pupupView的frame沒(méi)有被初始化)36 */37 - (UIView *)popupView {38     if (_popupView == nil) {39         // 初始化彈出view40         UIView *popupView = [[UIView alloc] init];41         CGFloat popupViewX = 0;42         CGFloat popupViewY = [UIApplication sharedApplication].statusBarFrame.size.height + self.navigationController.navigationBar.frame.size.height;43         CGFloat popupViewWidth = self.navigationController.navigationBar.frame.size.width;44         CGFloat popupViewHeight = self.view.frame.size.height - popupViewY - self.tabBarController.tabBar.frame.size.height;45         popupView.frame = CGRectMake(popupViewX, popupViewY, popupViewWidth, popupViewHeight);46         popupView.backgroundColor = [UIColor grayColor];47        48         UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 100)];49         label.text = @"這是全部彩種de彈出內(nèi)容";50         [popupView addSubview:label];51        52         self.popupView = popupView;53         NSLog(@"%@", NSStringFromCGRect(self.popupView.frame));54     }55    56     return _popupView;57 }58 59 /** 標(biāo)題點(diǎn)擊事件 60 * 轉(zhuǎn)換箭頭方向61 * 伸縮內(nèi)容62 */63 - (IBAction)titleClicked:(TitleExtendButton *)sender {64     [UIView animateWithDuration:0.5 animations:^{65         // 按鈕旋轉(zhuǎn)66         sender.imageView.transform = CGAffineTransformRotate(sender.imageView.transform, M_PI);67     }];68    69     // 彈出view70     if (![self.popupView isDescendantOfView:self.view]) {71         [self.view addSubview:self.popupView];72     } else {73         [self.popupView removeFromSuperview];74     }75 }76 @end
 
Image(10)
 
4.view的初始化方法
(1)awakeFromNib和initWithCoder:差別
awakeFromNib 從xib或者storyboard加載完畢就會(huì)調(diào)用
initWithCoder: 只要對(duì)象是從文件解析來(lái)的,就會(huì)調(diào)用
同時(shí)存在會(huì)先調(diào)用initWithCoder:
 
(2)initWithCoder: & initWithFrame:
initWithCoder:使用文件加載的對(duì)象調(diào)用(如從xib或stroyboard中創(chuàng)建)
initWithFrame:使用代碼加載的對(duì)象調(diào)用(使用純代碼創(chuàng)建)
     注意:所以為了同時(shí)兼顧從文件和從代碼解析的對(duì)象初始化,要同時(shí)在initWithCoder: 和 initWithFrame: 中進(jìn)行初始化
 
5.使用不同版本Xcode編譯代碼的時(shí)候,進(jìn)行適配
#import <Availability.h> 定義了SDK版本的宏
 1 #define __IPHONE_2_0     20000 2 #define __IPHONE_2_1     20100 3 #define __IPHONE_2_2     20200 4 #define __IPHONE_3_0     30000 5 #define __IPHONE_3_1     30100 6 #define __IPHONE_3_2     30200 7 #define __IPHONE_4_0     40000 8 #define __IPHONE_4_1     40100 9 #define __IPHONE_4_2     4020010 #define __IPHONE_4_3     4030011 #define __IPHONE_5_0     5000012 #define __IPHONE_5_1     5010013 #define __IPHONE_6_0     6000014 #define __IPHONE_6_1     6010015 #define __IPHONE_7_0     7000016 #define __IPHONE_7_1     7010017 #define __IPHONE_8_0     8000018 #define __IPHONE_8_1     80100
 
6.iOS6 和 iOS7 的簡(jiǎn)單適配
由于iOS6及之前的版本,屏幕view的位置尺寸是需要去掉狀態(tài)欄、導(dǎo)航欄等的位置尺寸的
而iOS7及之后的版本,屏幕view的位置尺寸默認(rèn)是占據(jù)了整個(gè)屏幕
這里需要設(shè)置iOS6 和 iOS7, 控制view的frame坐標(biāo)原點(diǎn)都是一樣的
(1)iOS7 中 view的擴(kuò)展效果
iOS7其實(shí)是增加了一個(gè)擴(kuò)展屬性,才能將屏幕view擴(kuò)展到全屏幕
由于不是TableController或者ScrollController的view不需要滾動(dòng),所以不需要進(jìn)行擴(kuò)展
擴(kuò)展屬性:self.edgesForExtendedLayout
 
在storyboard修改擴(kuò)展屬性,取消擴(kuò)展,默認(rèn)使用iOS6的做法:
修改控制器的屬性
0402DA0F-99A6-4477-9AA4-4E6D6EE105D0
 
取消勾選之后,會(huì)發(fā)現(xiàn)圖片位置的Y是從導(dǎo)航欄下端開(kāi)始的(跟iOS6一致)
Image(11)
 
運(yùn)行效果:
Image(12)
 
#mark:由于系統(tǒng)是OXS10.10.1, Xcode6.1.1,這里我沒(méi)有iOS6的模擬器,暫時(shí)試驗(yàn)不了iOS6的運(yùn)行情況
 
(2)啟動(dòng)圖的大小會(huì)決定app運(yùn)行的大小
使用較小的啟動(dòng)圖在較大尺寸的設(shè)備上運(yùn)行,會(huì)出現(xiàn)黑邊
     例如在4英寸的設(shè)備上使用iOS6進(jìn)行模擬,卻最大只有3.5英寸 retina(2x)的圖片,最后顯示的效果就是3.5英寸設(shè)備的顯示效果
 
給運(yùn)行iOS6的4英寸設(shè)備增加retina4(4英寸retina)的啟動(dòng)圖片
Image(13)
 
 
#mark:新出的iphone6(4.7英寸)和 iphone6 plus(5.5英寸)使用哪個(gè)尺寸的啟動(dòng)圖片?
#A:經(jīng)過(guò)試驗(yàn)證明是使用了 retina 4 的啟動(dòng)圖,如果不存在就會(huì)使用 2x 的啟動(dòng)圖,會(huì)造成上述的黑邊效果
 
刪掉 retina 4 的啟動(dòng)圖
Image(14)
 
運(yùn)行:
Image(15)
 
開(kāi)啟后:
Image(16)
 
 
7.設(shè)置按鈕的背景
(1)背景圖片拉伸方式(從中間某段開(kāi)始拉伸)
     之前在“聊天Demo”中,曾經(jīng)使用過(guò)代碼來(lái)設(shè)置UIImageView的圖片拉伸方式(聊天框背景),其實(shí)UIImageView也可以在storyboard中進(jìn)行拉伸設(shè)置:
Image(17)
 
Stretching(拉伸):
x: 左邊需要保護(hù)的比例(右邊由width影響)
y: 上邊需要保護(hù)的比例(下邊由height影響)
width:除去左邊需要保護(hù)的部分,拉伸寬度部分的比例(0代表1像素)
height:除去上邊需要保護(hù)的部分,拉伸高度部分的比例(0代表1像素)
 
在這里我們需要對(duì)一個(gè)UIButton進(jìn)行拉伸,但是storyboard不能對(duì)UIButton進(jìn)行此操作,會(huì)無(wú)效
Image(18)
 
----->所以需要使用代碼來(lái)進(jìn)行設(shè)置
stretchableImageWithLeftCapWidth
做成UIImage的一個(gè)分類方法
 1 // 2 //  UIImage+Extend.m 3 //  HelloLottery 4 // 5 //  Created by hellovoidworld on 15/1/3. 6 //  Copyright (c) 2015年 hellovoidworld. All rights reserved. 7 // 8  9 #import "UIImage+Extend.h"10 11 @implementation UIImage(Extend)12 13 /**  返回一個(gè)中心擴(kuò)展拉伸的圖片 */14 + (UIImage *) resizableImage:(NSString *) imageName {15     UIImage *image = [UIImage imageNamed:imageName];16    17     // 這個(gè)參數(shù)決定了左邊的保護(hù)區(qū)域,右邊的保護(hù)區(qū)域?yàn)樽筮?1開(kāi)始到末端18     CGFloat width = image.size.width * 0.5;19    20     // 原理同左右保護(hù)區(qū)域21     CGFloat height = image.size.height * 0.5;22    23     // 也就是,取中間1x1的區(qū)域作為擴(kuò)展區(qū)域24     return [image stretchableImageWithLeftCapWidth:width topCapHeight:height];25 }26 27 @end
 
(2)在登陸控制器中設(shè)置按鈕樣式
Image(19)
 
 1 // 2 //  HVWLoginViewController.m 3 //  HelloLottery 4 // 5 //  Created by hellovoidworld on 15/1/3. 6 //  Copyright (c) 2015年 hellovoidworld. All rights reserved. 7 // 8  9 #import "HVWLoginViewController.h"10 #import "UIImage+Extend.h"11 12 @interface HVWLoginViewController ()13 14 /** 登陸按鈕 */15 @property (weak, nonatomic) IBOutlet UIButton *loginButton;16 17 @end18 19 @implementation HVWLoginViewController20 21 - (void)viewDidLoad {22     [super viewDidLoad];23     // Do any additional setup after loading the view.24    25     UIImage *normal = [UIImage resizableImage:@"RedButton"];26     UIImage *highlighted = [UIImage resizableImage:@"RedButtonPressed"];27    28     [self.loginButton setBackgroundImage:normal forState:UIControlStateNormal];29     [self.loginButton setBackgroundImage:highlighted forState:UIControlStateHighlighted];30 }31 32 - (void)didReceiveMemoryWarning {33     [super didReceiveMemoryWarning];34     // Dispose of any resources that can be recreated.35 }36 37 38 @end
 
 
Image(20)
 
 
8.storyboard添加“設(shè)置”界面(暫時(shí)演示用)
"我的彩票" --> 右上角 "設(shè)置"
使用TableViewController
使用static cell顯示內(nèi)容
使用“customer”為cell的樣式,自行拖入image、label和switch等
Image(21)
 
 
9.設(shè)置按鈕主題,統(tǒng)一設(shè)置Navigation導(dǎo)航欄按鈕樣式
4DF79557-9C0D-470B-A774-D048C3666EBA
 
 
 
 
 
 
 

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 民丰县| 达州市| 沁源县| 玉龙| 乌拉特后旗| 五华县| 腾冲县| 吉水县| 玉门市| 汝南县| 离岛区| 桐乡市| 济源市| 信阳市| 乐安县| 渝北区| 子洲县| 墨江| 萍乡市| 攀枝花市| 福建省| 浙江省| 章丘市| 汝城县| 英超| 扎赉特旗| 墨竹工卡县| 开远市| 普兰县| 隆德县| 元氏县| 眉山市| 边坝县| 芦溪县| 富锦市| 长乐市| 汉中市| 皮山县| 信阳市| 正安县| 峨眉山市|