0
    CGFloat width = textField.text.floatValue;
    CGFloat height = textField2.text.floatValue;
    CanvasView *canv = [[CanvasView alloc]     initWithFrame:CGRectMake((self.myscrollview.frame.size.width - width)/2, (self.myscrollview.frame.size.height - height)/2, width, height)];
    [canv setBackgroundColor:[UIColor whiteColor]];
    self.canvas = canv;
    [self.myscrollview addSubview:canv];

我正在使用此代码UIView在运行时在 a中添加 a ,UIScrollView并且widthand参数是在运行时height从用户那里获取的,但问题是: 如果and大于其大小,则它不显示水平滚动条。
widthheightUIScrollView

为什么是这样?

4

3 回答 3

1

尝试设置self.myscrollview.showsHorizontalScrollIndicator = YES

祝你好运!

于 2013-08-08T11:57:44.937 回答
1

问题似乎contentSize在于scrollView.

widthheight增加比你必须相应地改变contentSizeUIScrollView

contentSize定义了要显示的可滚动内容的限制scrollview

scrollView.contentSize = CGSizeMake(width, height);

如果scrollview你只有UIView上面的代码行在任何情况下都必须工作。否则,您需要相应地设置 contentSize 以包含其他内容UIComponents

于 2013-08-08T12:06:19.280 回答
0

您必须将滚动视图框架设置为您想要的屏幕尺寸(即可见区域)。只有您设置滚动视图内容大小。

CGFloat width = textField.text.floatValue;
CGFloat height = textField2.text.floatValue;
self.myscrollview.frame=CGRectMake(0, 0, 768, 1004);
CGSizeMake contentOffset;
contentOffset = CGSizeMake(width, height);
[self.myscrollview. setContentSize:contentOffset animated:NO];


CanvasView *canv = [[CanvasView alloc]     initWithFrame:CGRectMake(0, 0, width, height)];
[canv setBackgroundColor:[UIColor whiteColor]];
self.canvas = canv;
[self.myscrollview addSubview:canv];

那么如果你想要滚动指示器,你可以使用

self.myscrollview.showsHorizontalScrollIndicator = YES;
于 2013-08-08T12:07:05.283 回答