【发布时间】:2014-08-11 07:13:18
【问题描述】:
你能帮帮我吗?我想通过滚动添加背景图片,因为我的背景图片太高了。我怎样才能做到这一点?我添加 UIScrollView 并添加 UIImageView 但它不滚动。
感谢您的回复。
【问题讨论】:
标签: xcode uiscrollview uiimageview
你能帮帮我吗?我想通过滚动添加背景图片,因为我的背景图片太高了。我怎样才能做到这一点?我添加 UIScrollView 并添加 UIImageView 但它不滚动。
感谢您的回复。
【问题讨论】:
标签: xcode uiscrollview uiimageview
这是工作代码:
- (void)viewDidLoad
{
[super viewDidLoad];
//create scrollView and set the frame to the size you want.
//In this example the scrollView frame is the whole ViewController size
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[scrollView setBackgroundColor:[UIColor clearColor]];
//create a UIImage,set the imageName to your image name
UIImage *image = [UIImage imageNamed:@"YourImageName.png"];
//create UIImageView and set imageView size to you image height
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, image.size.height)];
[imageView setImage:image];
//add ImageView to your scrollView
[scrollView addSubview:imageView];
//set content size of you scrollView to the imageView height
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, imageView.frame.size.height)];
[self.view addSubview:scrollView];
}
【讨论】:
如果您希望滚动视图滚动,请将内容大小设置为大于滚动视图框架。
【讨论】: