Three20 在xcode4.0上添加步驟

1.引言 

   今天剛接觸到three320  主要是遇到一個難題就是大量的文字在lable 上顯示的時候,顯示不同的字體,簡單的方法採用兩個lable 來顯示,但數據一但很多的時候或則交錯的時候是行不通的,所以纔想別的方法。下面談談自己一個下午的初體會

2.three 20 是什麼

three20 是從第三方facebook 剝離出的一個框架, 主要涉及三大模塊,網絡 ,stysle 和ui

突破了原有的模式,可以方便的定製出適合的界面風格,實現很多神奇的效果




如果想模仿iPhone郵件應用中的郵件編輯器,可以使用TTMessageController組件;如果想採用像Facebook那樣的消息發送窗口,可以使用TTPostController組件。


還有支持Safari和YouTube的視圖控制器。


Three20有一個功能強大的表格結構:單元格/條目結構。它在標準的蘋果單元格類型基礎上添加了幾種特殊的單元格類型。通過它可以方便地創建一些包含內嵌控件的表格視圖控制器。例如:




如果想在應用程序中顯示一個更小的活動指示器,可以使用Three20中的活動標籤,它提供了指示器+文本+進度條的顯示方式。


使用TTLauncherView組件來模擬iPhone的桌面。


支持在頂部的分頁標籤。


樣式(Style)
Three20的樣式組件能非常方便的聲明和複用。通過自定義樣式表, 可以用幾個簡單的聲明就可以創建可以圓角的按鈕、陰影、漸變和邊框。下面是幾個樣式表元素的例子:


上面的這些例子在官方的文檔裏都有具體的可實現的例子,而且對各個類和模塊怎樣使用都有很好的說明。引用這樣的一個第三庫可以節約很多時間。

 

3怎樣添加這個第三庫到xcode 四中去

在官方文檔裏面有很詳細的英文教程,網上有很多關於怎樣添加到xcode3.2 版本的教程,xcode4和前一個版本變化真的很大,那些教程摸索了好久也沒找到對應的項,只好看英文版的。

添加到第三方庫到以存在的工程有兩種方式

(1)使用命令

(2) 手動加載

手動的沒怎麼看明白,感覺還是命令的方式比較好,相當的簡單

3.1 下載源代碼

https://github.com/facebook/three20/archives/master

(下載好源代碼後把文件最好解壓到你的現有工程的文件目錄下)

3.2打開mac 的終端

輸入以下命令(最好用命令切換到工程目錄,命令裏面的路徑改下,改成對應的目錄)

  1. python three20/src/scripts/ttmodule.py -p path/to/your/project/project.xcodeproj Three20 --xcode-version=4 

 

3,3打開目錄就可以看到工程加載到你的工程目錄下了

 

 

在你的工程的prefix-pch 中添加 #import <Three20/Three20+Additions.h>

這樣每個類都可以使用這格第三方庫文件了()

在文件種添加下面幾個簡單的代碼

 

  1. @implementation TextTestStyleSheet 
  2.  
  3. - (TTStyle*)blueText { 
  4.     return [TTTextStyle styleWithColor:[UIColor blueColor] next:nil]; 
  5.  
  6. - (TTStyle*)largeText { 
  7.     return [TTTextStyle styleWithFont:[UIFont systemFontOfSize:32] next:nil]; 
  8.  
  9. - (TTStyle*)smallText { 
  10.     return [TTTextStyle styleWithFont:[UIFont systemFontOfSize:12] next:nil]; 
  11.  
  12. - (TTStyle*)floated { 
  13.     return [TTBoxStyle styleWithMargin:UIEdgeInsetsMake(0, 0, 5, 5) 
  14.                                padding:UIEdgeInsetsMake(0, 0, 0, 0) 
  15.                                minSize:CGSizeZero position:TTPositionFloatLeft next:nil]; 
  16.  
  17. - (TTStyle*)blueBox { 
  18.     return 
  19.     [TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:6] next: 
  20.      [TTInsetStyle styleWithInset:UIEdgeInsetsMake(0, -5, -4, -6) next: 
  21.       [TTShadowStyle styleWithColor:[UIColor grayColor] blur:2 offset:CGSizeMake(1,1) next: 
  22.        [TTSolidFillStyle styleWithColor:[UIColor cyanColor] next: 
  23.         [TTSolidBorderStyle styleWithColor:[UIColor grayColor] width:1 next:nil]]]]]; 
  24.  
  25. - (TTStyle*)inlineBox { 
  26.     return 
  27.     [TTSolidFillStyle styleWithColor:[UIColor blueColor] next: 
  28.      [TTBoxStyle styleWithPadding:UIEdgeInsetsMake(5,13,5,13) next: 
  29.       [TTSolidBorderStyle styleWithColor:[UIColor blackColor] width:1 next:nil]]]; 
  30.  
  31. - (TTStyle*)inlineBox2 { 
  32.     return 
  33.     [TTSolidFillStyle styleWithColor:[UIColor cyanColor] next: 
  34.      [TTBoxStyle styleWithMargin:UIEdgeInsetsMake(5,50,0,50) 
  35.                          padding:UIEdgeInsetsMake(0,13,0,13) next:nil]]; 
  36.  
  37. @end 
  38.  
  39.  
  40.   
  41.     NSString* kText = @"\ 
  42.     This is a test of styled labels.  Styled labels support \ 
  43.     <b>bold text</b>, <i>italic text</i>, <span class=\"blueText\">colored text</span>, \ 
  44.     <span class=\"largeText\">font sizes</span>, \ 
  45.     <span class=\"blueBox\">spans with backgrounds</span>, inline p_w_picpaths \ 
  46.     <img src=\"bundle://smiley.png\"/>, and <a href=\"http://www.google.com\">hyperlinks</a> you can \ 
  47.     actually touch. URLs are automatically converted into links, like this: http://www.foo.com\ 
  48.     <div>You can enclose blocks within an HTML div.</div>\ 
  49.     Both line break characters\n\nand HTML line breaks<br/>are respected."; 
  50.     
  51.        
  52.     TTStyledTextLabel* label1 = [[[TTStyledTextLabel alloc] initWithFrame:CGRectMake(0, 10, 320, 480)] autorelease]; 
  53.     label1.font = [UIFont systemFontOfSize:17]; 
  54.     label1.text = [TTStyledText textFromXHTML:kText lineBreaks:YES URLs:YES]; 
  55.     label1.contentInset = UIEdgeInsetsMake(10, 10, 10, 10); 
  56.     //label1.backgroundColor = [UIColor grayColor]; 
  57.     [label1 sizeToFit]; 
  58.     [self.view addSubview:label1];} 

 

效果如下

 

 


初步研究,歡迎指正。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章