0
嗨,我想创建使用的UIScrollView如何绘制自定义形状里面的UIScrollView
- 我想创建介绍我自己的时间线视图(需要使用石英库绘制),它的尺寸为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);
}
- 同现在我想创建月视图使用相同类型的绘制代码:
示例代码:
- (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;
}
}
,但如果我滚动我的滚动视图什么都我在该视图中绘制不滚动,如果在我的代码中的任何错误,或者任何其它最好的方法为了达成这个。
好心劝我。
在此先感谢。
我想你错过了所有要在scrollview中添加内容的东西,并为scrollview提供适当的内容大小 –
尝试使用UIView子类,并使用它的drawRect:方法来绘制,然后将其作为子视图显示在您的滚动视图中。 –
我在UIScrollView子类的drawRect:方法内部调用了这个方法。在滚动视图的同时,自定义绘制不会随视图一起滚动。而我的scroll view contentSize是(1200,1200) – nagarajan