2014-03-03 34 views
0

嗨,我想創建使用的UIScrollView如何繪製自定義形狀裏面的UIScrollView

  1. 我想創建介紹我自己的時間線視圖(需要使用石英庫繪製),它的尺寸爲1200,50。

示例代碼:

- (void)drawYearScaleMain 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetRGBFillColor(context, 1.0, 0.6, 0.2, 0.8); 
    CGContextMoveToPoint(context, self.bounds.origin.x, self.bounds.origin.y); 
    CGContextAddLineToPoint(context, self.contentSize.width, self.bounds.origin.y); 
    CGContextAddLineToPoint(context, self.contentSize.width, 50); 
    CGContextAddLineToPoint(context, self.bounds.origin.x, 50); 
    CGContextAddLineToPoint(context, self.bounds.origin.x, self.bounds.origin.y); 
    CGContextFillPath(context); 
} 
  1. 同現在我想創建月視圖使用相同類型的繪製代碼:

示例代碼:

- (void)drawMonthScaleSub 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetRGBFillColor(context, 0.0, 0.6, 0.2, 0.8); 

    CGFloat topLeftX = self.bounds.origin.x; 
    CGFloat topLeftY = 50; 
    CGFloat width = 98; 
    CGFloat height = 30; 

    for(int count = 0; count<12; count++) 
    { 
     CGRect frame = CGRectMake(topLeftX, topLeftY, width, height); 
     CGContextFillRect(context, frame); 
     topLeftX = topLeftX + 10 + width; 
    } 

} 

,但如果我滾動我的滾動視圖什麼都我在該視圖中繪製不滾動,如果在我的代碼中的任何錯誤,或者任何其它最好的方法爲了達成這個。

好心勸我。

在此先感謝。

+0

我想你錯過了所有要在scrollview中添加內容的東西,併爲scrollview提供適當的內容大小 –

+0

嘗試使用UIView子類,並使用它的drawRect:方法來繪製,然後將其作爲子視圖顯示在您的滾動視圖中。 –

+0

我在UIScrollView子類的drawRect:方法內部調用了這個方法。在滾動視圖的同時,自定義繪製不會隨視圖一起滾動。而我的scroll view contentSize是(1200,1200) – nagarajan

回答

0

我認爲你應該做一個UIView的子類並重新實現DrawRect:方法。那麼你應該把這個視圖放在你的scrollView中。