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

iPhone文本切頁(yè)代碼案例實(shí)現(xiàn)

移動(dòng)開(kāi)發(fā) iOS
iPhone文本切頁(yè)代碼案例實(shí)現(xiàn)是本文要介紹的內(nèi)容,主要是來(lái)學(xué)習(xí)文本是如何來(lái)切頁(yè)的,本文主要是基于代碼實(shí)現(xiàn)內(nèi)容,來(lái)看具體實(shí)現(xiàn)代碼。

iPhone文本切頁(yè)代碼案例實(shí)現(xiàn)是本文要介紹的內(nèi)容,主要是來(lái)學(xué)習(xí)文本是如何來(lái)切頁(yè)的,本文主要是基于代碼實(shí)現(xiàn)內(nèi)容,來(lái)看具體實(shí)現(xiàn)代碼。

  1. //!如果不是HTML,可以把</p>改為n或者rn  
  2. -(NSString *)doPagination:(NSString *)pageContent pageNumber:(NSInteger)number  
  3.                                  fontSize:(NSInteger)size lineHeight:(NSInteger)lheight pageHeight:(NSInteger)pheight  
  4. pageWidth:(NSInteger) pwidth{  
  5.     UIFont *tfont=[UIFont fontWithName:@"Helvetica" size:size];  
  6.     CGFloat singleHeight=[@"中" sizeWithFont:tfont constrainedToSize:CGSizeMake((float)pwidth, 9999.0) 
  7. lineBreakMode:UILineBreakModeCharacterWrap ].height;  
  8.     NSInteger maxline_per_page=(int) (pheight/singleHeight);  
  9.     NSArray *paragraphSplit=[pageContent componentsSeparatedByString:@"</p>"];  
  10.     NSString *breakString=@"nn";  
  11.     NSString *contentTrim;  
  12.     NSInteger totalLines=0;  
  13.     NSMutableString *tempString=[NSMutableString string];  
  14.     NSString *leftString;  
  15.     CGSize csize;  
  16.     NSMutableArray *bookPages=[NSMutableArray array];  
  17.     for (NSString *para in paragraphSplit){  
  18.         contentTrim=[para stringByReplacingOccurrencesOfString:@"<p>" withString:breakString];  
  19.         csize=[contentTrim sizeWithFont:tfont constrainedToSize:CGSizeMake((float)pwidth, MAXFLOAT) 
  20. lineBreakMode:UILineBreakModeCharacterWrap ];  
  21.         totalLines+=(int)(csize.height/singleHeight);  
  22.         leftString=contentTrim;  
  23.         if (totalLines > maxline_per_page){  
  24.             totalLines-=(int)(csize.height/singleHeight);  
  25.             for(int i=0;i<[contentTrim length];i++){  
  26.                 NSString *calcString=[contentTrim substringWithRange:NSMakeRange(0, i)];  
  27.                 csize=[calcString sizeWithFont:tfont constrainedToSize:CGSizeMake((float)pwidth, MAXFLOAT) 
  28. lineBreakMode:UILineBreakModeCharacterWrap ];  
  29.                 totalLinestotalLines=totalLines+(int)(csize.height/singleHeight);  
  30.                 if (totalLines>maxline_per_page)  
  31.                 {  
  32.                     i--;  
  33.                     if ([calcString length]>0) [tempString appendString:[calcString substringToIndex:([calcString length]-1)]];  
  34.                     if (i>0) leftString=[contentTrim substringFromIndex:i]; else leftString=@"";  
  35.                     [bookPages addObject:[[tempString copy]autorelease]];  
  36.                     totalLines=(int)([leftString sizeWithFont:tfont constrainedToSize:CGSizeMake((float)pwidth, MAXFLOAT) 
  37. lineBreakMode:UILineBreakModeCharacterWrap ].height/singleHeight);  
  38.                     [tempString setString:@""];  
  39.                     break;  
  40.                 }  
  41.                 else totalLinestotalLines=totalLines-(int)(csize.height/singleHeight);  
  42.             }  
  43.         }  
  44.         [tempString appendString:leftString];  
  45.     }  
  46.     [bookPages addObject:[[tempString copy]autorelease]];  
  47.     self.bookContent=[NSArray arrayWithArray:bookPages];  
  48.     return [bookPages objectAtIndex:number];  

小結(jié):iPhone文切頁(yè)代碼案例實(shí)現(xiàn)的內(nèi)容介紹完了,希望通過(guò)本文的學(xué)習(xí)能對(duì)你有所幫助。

責(zé)任編輯:zhaolei 來(lái)源: cocoachina
相關(guān)推薦

2011-08-19 10:05:30

iPhone開(kāi)發(fā)

2011-08-18 16:42:07

iPhone應(yīng)用APNS推送

2011-08-18 16:03:34

iPhone上傳圖片

2011-08-15 15:44:46

iPhone開(kāi)發(fā)PDF

2011-08-18 16:24:44

iPhone開(kāi)發(fā)圖片

2011-08-09 14:54:29

iPhoneNSDateanotherDate

2011-08-19 11:10:31

iPhone應(yīng)用

2011-08-19 10:13:05

iPhone開(kāi)發(fā)

2011-08-16 15:48:37

iPhone開(kāi)發(fā)抓圖程序

2011-08-19 10:39:01

iPhone App輸入面板

2011-07-20 15:20:14

IPhone AVAudioRec

2011-08-19 17:02:46

iPhone開(kāi)發(fā)

2011-08-16 15:36:47

iPhone應(yīng)用測(cè)試

2011-08-17 16:23:31

iPhone開(kāi)發(fā)UIViewContr

2011-08-17 16:12:20

iPhone應(yīng)用程序

2011-08-18 15:24:40

iPhone國(guó)際化

2011-07-27 11:19:33

iPhone UITableVie

2011-08-19 10:01:09

iPhone應(yīng)用SqliteUITableView

2011-08-17 16:29:12

iPhone開(kāi)發(fā)UIButton

2011-07-25 14:44:41

iPhone iPhone開(kāi)發(fā) 截屏
點(diǎn)贊
收藏

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