2009-10-22 40 views
3

我嘗試使用Tweetie的創建者Loren Brichter的technique(或this technique)創建快速滾動列表。我相信這個想法是「做你自己的繪圖」,而不是在UITableViewCell中使用子視圖和圖像。使用圖像快速滾動表格單元格。這是怎麼完成的?

下面我將他的示例擴展爲包含圖像,我不確定這是否是正確的方法?

我一直在試圖與CALayer玩弄,並努力'得到它'。所以在這個例子中,我只是繪製出一張圖片。但我不確定 - 這與圖像在視圖中的顯示方式相同?接下來,我將使用UIGraphicsBeginImageContext來包含更多圖像(例如footerImage)

在本示例中,我正在做什麼來提高性能而不是在IB中創建它?

感謝

- (void)drawContentView:(CGRect)r 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    UIColor *backgroundColor = [UIColor whiteColor]; 
    UIColor *textColor = [UIColor blackColor]; 

    if(self.selected) 
    { 
     backgroundColor = [UIColor clearColor]; 
     textColor = [UIColor whiteColor]; 
    } 

    [backgroundColor set]; 
    CGContextFillRect(context, r); 

    // This is where I add the image to the example 
    // 
    CGRect profile = CGRectMake(0, 0, 320, 20); 
    [headerImage drawInRect:profile]; 

    CGPoint p; 
    p.x = 12; 
    p.y = 9; 

    [textColor set]; 
    CGSize s = [firstText drawAtPoint:p withFont:firstTextFont]; 

    p.x += s.width + 6; // space between words 
    [lastText drawAtPoint:p withFont:lastTextFont]; 
} 
+0

由於Loren的博客已不在線,因此文章鏈接被中斷。以下指向存檔版本的鏈接。 [用UITableView快速滾動Tweetie](http://web.archive.org/web/20100922230053/http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/) – robotpukeko 2012-07-23 21:33:16

+0

@robotpukeko謝謝,更新。還添加了另一個鏈接... – Ross 2012-07-24 11:32:28

回答

3

是,這種技術將提高在直IB電池性能。但是如果你讓一個單元格的所有元素都不透明,那麼IB性能可能相當不錯 - 你可能要先嚐試一下,然後再沿着很多代碼的路徑創建其他簡單的單元格。

相關問題