成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

小型企業商務應用程序設計及開發系列(3):自定義視圖

譯文
移動開發
歡迎大家閱讀小型企業商務應用程序設計及開發系列教程的最后一部分。在第三篇文章中,我們將共同學習如何設計并創建出飽含構思與靈感的視圖,進而讓公司服務以更鮮活的方式呈現在用戶面前。

教程說明

  • 技術工具: iOS SDK
  • 操作難度: 普通
  • 執行時間: 30 到60分鐘

【51CTO譯文】歡迎大家閱讀小型企業商務應用程序設計及開發系列教程的最后一部分。在第三篇文章中,我們將共同學習如何設計并創建出飽含構思與靈感的視圖,進而讓公司服務以更鮮活的方式呈現在用戶面前。

教程概述

在本篇文章中,我將與大家共同探討如何設計商務應用程序的最后一環——企業服務信息界面,并嘗試以美觀簡潔的方式向用戶展示更詳盡的內容。

在本節內容完成后,我們的應用程序將如下圖所示:

file0002.png

屏幕內容在外觀及使用感受上與網站專題非常相似,包含了標題、圖片、作者等一系列除內容之外的描述信息。這一設計靈感源自BizApp iPhone應用設計模板。全部內容都將由UIWebView實現,我們可以在其中添加豐富的內容鏈接以及排版布局。

創建UI元素

首先在Xcode項目中添加一個新的視圖控制器,并將其命名為DetailViewController。打開DetailViewController.h文件,并將以下域加入初始位置——這些就是我們要在視圖中使用到的UI元素。

  1. @interface DetailViewController : UIViewController 
  2.   
  3. @property (nonatomic, strong) UILabel *titleLabel; 
  4.   
  5. @property (nonatomic, strong) UIImageView *articleImageView; 
  6.   
  7. @property (nonatomic, strong) UILabel* metaLabel; 
  8.   
  9. @property (nonatomic, strong) UILabel* nameLabel; 
  10.   
  11. @property (nonatomic, strong) UIWebView* articleWebView; 
  12.   
  13. @property (nonatomic, strong) UIScrollView* scrollView; 
  14. @end 

在DetailViewController文件中,我們需要創建這些域并將其插入視圖當中。現在ViewDidLoad方法中已經一切就緒。

別忘了將這些域添加到文件開頭。

  1. @synthesize titleLabel, articleWebView, articleImageView, metaLabel, nameLabel, scrollView; 

首先要插入到ViewDidLoad方法當中的兩個元素分別是滾視圖及標簽。UI標簽與滾動視圖相結合,用戶才能通過滑動操作閱讀屏幕下方尚未顯示出來的信息。

  1. self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
  2. [self.view addSubview:scrollView]; 
  3.       
  4. self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 300, 61)]; 
  5. [titleLabel setFont:[UIFont boldSystemFontOfSize:20]]; 
  6. [titleLabel setNumberOfLines:2]; 
  7. [scrollView addSubview:titleLabel]; 

接下來要插入的元素是本章本身的圖像:

  1. self.articleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 58, 320, 109)]; 
  2. [articleImageView setContentMode:UIViewContentModeScaleAspectFill]; 
  3. [articleImageView setClipsToBounds:YES]; 
  4. [scrollView addSubview:articleImageView]; 

SetContentMode屬性能夠確保圖像始終保持原始狀態(不會被拉伸),而SetClipsToBounds屬性則用來保證圖像不會超過對應區塊的邊界。完成之后,我們要處理的是圖像下方的兩個標簽:

  1. self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 169, 170, 21)]; 
  2. [nameLabel setFont:[UIFont systemFontOfSize:13]]; 
  3. [nameLabel setText:@"By John Doe / Posted under: "]; 
  4. [scrollView addSubview:nameLabel]; 
  5.   
  6. self.metaLabel = [[UILabel alloc] initWithFrame:CGRectMake(183, 169, 117, 21)]; 
  7. [metaLabel setFont:[UIFont systemFontOfSize:13]]; 
  8. [metaLabel setTextColor:[UIColor colorWithRed:30.0/255 green:144.0/255 blue:224.0/255 alpha:1.0]]; 
  9. [scrollView addSubview:metaLabel]; 

標簽本身為藍色,文本內容則使用系統中默認的13號字體。

然后是分隔線和web視圖,這里是顯示信息內容的重點區域。

  1. self.articleWebView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 204, 300, 700)]; 
  2. [scrollView addSubview:articleWebView]; 
  3.       
  4. UIView* dividerView = [[UIView alloc] initWithFrame:CGRectMake(10, 194, 300, 2)]; 
  5. [dividerView setBackgroundColor:[UIColor lightGrayColor]]; 
  6. [scrollView addSubview:dividerView]; 

到這里,我們已經完成了所有基本UI元素。現在把新的視圖控制器與Storyboard相關聯,這樣我們就能實現瀏覽操作了。

將視圖控制器添加到Storyboard當中

在MainStoryboard_iPhone文件中添加一個新的視圖控制器,選擇該視圖控制器并將類變更為DetailViewController。這樣才能確保我們在DetailViewController文件中執行的任何代碼都與新的視圖機制在Storyboard上保持匹配。

file0005.png

為了保證新的視圖控制器能夠在用戶觸摸網絡中的對應服務項目時生效,我們可以使用segue功能。這是iOS 5 SDK中新加入的功能,只需選擇Storyboard文件,按住Ctrl鍵并將其從GridViewController拖拽到DetailViewController即可。這時屏幕上會彈出幾個選項,選擇其中的“push”,這意味著新的視圖控制器將以普通UI界面視圖的形式顯示在屏幕中。

file0006.png

完成以上步驟后,為兩套視圖控制器建立鏈接(segue)。點擊segue圖標并將其命名為“detail”。

file0007.png

為了將最后一部分連接內容加入進來,我們需要打開GridViewController.m文件并添加以下代碼段:

  1. -(void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index 
  2.     [self performSegueWithIdentifier:@"detail" sender:self]; 

當網格中的項目被選定時,方法會執行名為“detail”的segue操作(我們在前面的步驟中剛剛創建完成)。

現在如果大家在模擬器運行應用程序并點擊網格中的項目,就會看到新的視圖從屏幕右側切入并替換掉當前界面。

不過現在切入的新界面還是一片空白,因為我們還沒有為其添加任何數據。

從模型中添加數據

下一步工作是從我們的數據模型中(在第二部分文章中創建完成)提取信息,并發往Detail視圖控制器。要做到這一點,我們首先需要用需要的數據擴展模型。

現在我們為模型文件DataModel.h添加三個額外的域,分別為標題、圖像以及文章內容。

  1. @interface Model : NSObject 
  2.   
  3. @property (nonatomic, copy) NSString* name; 
  4.   
  5. @property (nonatomic, retain) UIImage* image; 
  6.   
  7. @property (nonatomic, copy) NSString* webContentTitle; 
  8.   
  9. @property (nonatomic, copy) NSString* webContent; 
  10.   
  11. @property (nonatomic, retain) UIImage* webContentImage; 
  12.   
  13. -(id)initWithName:(NSString*)theName andImage:(UIImage*)theImage andWebContentTitle:(NSString*)theTitle andWebContent:(NSString*)theWebContent andWebContentImage:(UIImage*)theWebImage; 
  14.   
  15. @end 

然后將初始化方法引入DataModel.m文件。

  1. @synthesize name, image, webContent, webContentTitle, webContentImage; 
  2.  
  3. -(id)initWithName:(NSString*)theName andImage:(UIImage*)theImage andWebContentTitle:(NSString*)theTitle andWebContent:(NSString*)theWebContent andWebContentImage:(UIImage*)theWebImage 
  4.     self = [super init]; 
  5.       
  6.     if(self) 
  7.     { 
  8.         self.name= theName; 
  9.         self.image = theImage; 
  10.         self.webContent = theWebContent; 
  11.         self.webContentTitle = theTitle; 
  12.         self.webContentImage = theWebImage; 
  13.     } 
  14.       
  15.     return self; 

接下來就是向其中添加樣本數據。最好的辦法當然是從網絡服務端載入信息,但這就超出本文的討論范圍了,因此先放下不談。

為了節約字數,我只列出模型中的一條樣本數據。其它數據的形式都是一樣的,只是內容上有所不同。

  1. NSString *content = @"<p>Corporate law is the study of how shareholders, directors, employees, creditors, and other stakeholders such as consumers, the community and the environment interact with one another. </p><p>The four defining characteristics of the modern corporation are:</p> <ul><li>Separate Legal Personality of the corporation (access to tort and contract law in a manner similar to a person)</li><li>Limited Liability of the shareholders</li><li>Shares (if the corporation is a public company, the shares are traded on a stock exchange)</li><li>Delegated Management; the board of directors delegates day-to-day management</li><ul>"; 
  2.  
  3.       
  4.  
  5. BusinessService *service1 = [[BusinessService alloc] initWithCaption:@"Litigation" andImage:[UIImage imageNamed:@"service-1.jpg"] andWebContentTitle:@"Litigation: Peace of mind with the experts" andWebContent:content andWebContentImage:[UIImage imageNamed:@"service-1.jpg"]]; 

至于要添加進來的圖片,我們必須將其命名為“service-1.jpg”到“service-6.jpg”,并保存在項目中的樣本文件夾里。現在樣本數據就處理完成了,讓我們將其關聯到UI元素上,看看能不能正確顯示出來。

在屏幕上顯示數據

在DetailViewController.h文件中添加新的域,它的作用是擔當BuisinessService類的實例。別忘了把BusinessService頭文件也加進來,并付諸執行。

  1. @property (nonatomic, retain) BusinessService* service; 

在DetailViewController的ViewDidLoad方法中添加聲明,以保證所有UI元素及其對應的服務信息都被正確選中。

  1. [titleLabel setText:service.webContentTitle]; 
  2. [articleImageView setImage:service.webContentImage]; 
  3. [articleWebView loadHTMLString:service.webContent baseURL:nil]; 
  4. [metaLabel setText:service.caption]; 

現在我們可以運行應用程序了,點擊網格中的項目可以進入詳細視圖。最終顯示結果如下圖所示。

file0010.png

大家可以看到,現在我們的詳細視圖幾乎算是完成了。惟一的缺憾在于后退按鈕實在是太難看了,默認樣式與自定義導航欄實在是格格不入。

添加自定義UI菜單欄按鈕

為了解決這個問題,我們將使用資源文件夾中的“back.png”文件。要將該圖片設置為后退按鈕樣式,我們需要將以下代碼段添加到AppDelegate.m文件中的didFinishLaunchingWihOptions方法處。

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
  2.     UIImage *navBarImage = [UIImage imageNamed:@"menubar.png"]; 
  3.       
  4.     [[UINavigationBar appearance] setBackgroundImage:navBarImage 
  5.                                        forBarMetrics:UIBarMetricsDefault]; 
  6.       
  7.       
  8.     UIImage* backButtonImage = [UIImage imageNamed:@"back.png"]; 
  9.       
  10.     [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
  11.       
  12.     return YES; 

上述代碼的作用是讓應用程序利用iOS 5 SDK改變后退按鈕的外觀。現在運行應用程序,我們會發現顯示效果如下所示。

file0012.png

總結

這個系列的三篇文章到此終于全部告一段落。

希望大家現在對于應用程序設計有更深刻的理解,并以此為基礎在未來的開發工作中制作出獨一無二的精彩作品。

感謝大家的支持與耐心,如果還有什么問題或者意見,不妨在評論欄中共同探討。

原文鏈接:

http://mobile.tutsplus.com/tutorials/iphone/design-build-a-small-business-app-custom-detail-views/

 

責任編輯:佚名 來源: 51CTO.com
相關推薦

2012-08-21 09:26:52

小型企業商務應用項目設置

2012-08-22 08:37:37

小型企業商務應用AQGrid View

2012-02-15 14:39:55

GNOME 3

2012-08-31 11:28:07

惠普動能服務器NonStop NS2

2009-11-24 09:51:22

路由設計方案

2013-09-11 09:37:17

企業級移動應用

2016-08-23 13:21:15

MVC路由視圖

2010-03-04 10:11:17

Android手機系統

2022-05-04 23:08:36

標準Go應用程序

2019-10-08 10:12:26

安全黑客攻擊數據

2014-06-04 13:33:03

OpenStack云平臺

2011-09-22 09:12:11

小型企業云計算安全

2014-06-17 15:44:47

OpenStackApache 2.0

2011-06-03 10:31:25

小企業虛擬化

2010-08-25 17:45:21

2013-09-30 10:01:19

中小企業關鍵業務應用

2013-01-14 11:40:50

IBMdW

2011-02-24 09:56:26

組網網絡

2018-11-08 09:10:18

組網光纖網絡

2014-09-28 14:28:12

硬盤加密全盤加密
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产影音先锋 | 久久久婷婷 | 国产美女在线免费观看 | 色天堂视频 | h视频免费在线观看 | 国产成人综合久久 | 国产你懂的在线观看 | 国产亚洲一区二区三区在线观看 | 天天插天天操 | 免费看的黄网站 | 欧美性猛交一区二区三区精品 | 午夜日韩精品 | 成人在线影视 | 亚洲精品一区二区在线观看 | 日韩在线不卡 | 久久99精品久久久久蜜桃tv | 亚洲国产精品一区二区三区 | 亚洲大片在线观看 | 亚洲精品视频在线播放 | 99re在线视频观看 | 国产一级片一区二区 | 18成人在线观看 | 日本一二三区电影 | 一色桃子av一区二区 | 亚洲高清在线 | 午夜精品三区 | 91精品中文字幕一区二区三区 | 日韩久草 | 午夜三级在线观看 | 青草青草久热精品视频在线观看 | 精品国产一区二区国模嫣然 | 免费在线色 | 日韩在线小视频 | 久久国产视频播放 | 最新日韩精品 | 国产视频中文字幕在线观看 | 九九热九九 | 欧美日韩亚洲一区 | 一区二区免费高清视频 | 欧美激情一区二区三级高清视频 | 羞视频在线观看 |