自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開發(fā)九宮格代碼實現(xiàn)

移動開發(fā) iOS
本文介紹的是iPhone開發(fā)九宮格代碼實現(xiàn),講述了九宮格的是實現(xiàn)代碼,先來看詳細內(nèi)容。

iPhone開發(fā)九宮格代碼實現(xiàn)是本文要介紹的內(nèi)容,九宮格大家應(yīng)該很感興趣吧?那么本文就是來介紹九宮格的制作方法,先來看詳細內(nèi)容??吹紺ocoaChina很多同學(xué)在問,其實很簡單,我這是用圖片堆砌實現(xiàn)的九宮格,分享如下,代碼如下。

效果圖:

iPhone開發(fā)九宮格代碼實現(xiàn)

核心就這2個方法:

  1. //Power by ieliwb.com  
  2. - (void)viewDidLoad {  
  3.     [super viewDidLoad];  
  4.     NSArray* imageNames = [NSArray arrayWithObjects:                                    
  5. @"ico_mobile.png",                                    
  6. @"ico_idcard.png",                                 
  7. @"ico_postcode.png",                                   
  8.   @"ico_flight.png",                                        
  9.  @"ico_translate.png",                               
  10. @"ico_phone.png",                                       
  11. @"ico_car.png",                              
  12. @"ico_health.png",                                     
  13. @"ico_bjxm.png", nil];  
  14.     UIButton *Btn;  
  15.     for (int i=0; i<9; i++) {  
  16.         CGRect frame;  
  17.         Btn = [[UIButton buttonWithType:UIButtonTypeCustom] retain];  
  18.         [Btn setImage:[UIImage imageNamed:[imageNames objectAtIndex: i]] forState:UIControlStateNormal];//設(shè)置按鈕圖片  
  19.         Btn.tag = i;  
  20.         frame.size.width = 59;//設(shè)置按鈕坐標及大小  
  21.         frame.size.height = 75;  
  22.         frame.origin.x = (i%3)*(59+32)+40;  
  23.         frame.origin.y = floor(i/3)*(75+24)+40;  
  24.         [Btn setFrame:frame];  
  25.           
  26.         [Btn setBackgroundColor:[UIColor clearColor]];  
  27.         [Btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];  
  28.         [self.view addSubview:Btn];  
  29.         [Btn release];  
  30.     }  
  31. }  
  32.    
  33. //響應(yīng)按鈕事件  
  34. -(void)btnPressed:(id)sender{  
  35.     UIButton *Btn = (UIButton *)sender;  
  36.         int index = Btn.tag;  
  37.     switch (index) {  
  38.         case 0:  
  39.             if(mobileController==nil)  
  40.                 mobileController = [[MobileController alloc]init];  
  41.             [self.navigationController pushViewController:mobileController animated:YES];  
  42.             break;  
  43.         //其他幾個控制器類似  
  44.     }  

九宮格背景修改可以這樣實現(xiàn):

  1. - (void)loadView {  
  2.     UIImageView *contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];  
  3.     [contentView setImage:[UIImage imageNamed:@"subview_9_bg.png"]];  
  4.     [contentView setUserInteractionEnabled:YES];  
  5.     self.view = contentView;  
  6.     [contentView release];  

UINavigationBar背景圖片可以這樣實現(xiàn):

  1. @implementation UINavigationBar (CustomImage)  
  2. - (void)drawRect:(CGRect)rect {  
  3.     UIImage *image = [UIImage imageNamed: @"top_bg.png"];  
  4.     [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];  
  5. }  
  6. @end 

小結(jié):iPhone開發(fā)九宮格代碼實現(xiàn)的內(nèi)容介紹完了,希望本文對你有所幫助!

責(zé)任編輯:zhaolei 來源: 博客園
相關(guān)推薦

2015-01-26 13:22:55

密碼鎖

2019-03-24 15:05:23

手機安全解鎖

2013-05-29 10:44:11

2015-03-05 15:27:22

2018-08-14 13:34:30

商業(yè)模式

2021-12-31 08:12:05

微信微信支付云閃付

2013-07-30 11:16:33

iOS 7 Beta 九宮格輸入法

2011-09-16 10:35:13

Android應(yīng)用數(shù)獨經(jīng)典游戲

2022-04-21 21:49:57

元宇宙

2023-04-20 08:26:17

九宮格布局客戶端

2020-09-16 12:10:19

九宮格視頻Python文件

2022-03-03 18:49:56

HarmonyOS鴻蒙操作系統(tǒng)

2017-03-29 15:41:45

互聯(lián)網(wǎng)

2013-10-31 11:19:09

微軟語音翻譯手語翻譯

2011-05-25 19:35:25

2012-04-13 16:35:02

傲游手機瀏覽器發(fā)布

2021-10-12 16:39:39

支付寶口碑移動應(yīng)用

2019-08-06 16:40:33

手機按鍵屏幕

2013-07-30 14:25:51

蘋果iOS 7iTunes 11.1

2023-05-31 10:08:51

點贊
收藏

51CTO技術(shù)棧公眾號