Addsubview没有显示uiimageview

时间:2012-07-23 20:15:48

标签: iphone uiscrollview

尝试通过addsubview将uiimageview放在滚动视图上,但没有显示。这是viewDidLoad中的代码:

UIImage *buttonImage = [UIImage imageNamed:@"button"];
UIImageView *buttonImageview = [[UIImageView alloc] initWithImage:buttonImage];
buttonImageview.frame = (CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=buttonImage.size};
[self.scrollView addSubview:buttonImageview];

我做错了什么?

4 个答案:

答案 0 :(得分:2)

我确定你的意思

[UIImage imageNamed:@"button.png"]

- )

答案 1 :(得分:0)

我的想法: - 确保文件确实在编译资源中。 - 通过某些NSLog检查图像是否正确加载,打印图像的CGSize。 - 确保正确设置框架

你可以调用[UIImage imageNamed:@“按钮”],根据设备查找正确的视网膜或非图像

答案 2 :(得分:0)

Scrollview要求您在其上设置许多属性。特别是contentSize。您没有将原始问题中的代码包含在您分配和设置的位置,这可能是问题所在。没有看到它我只能假设,但你必须做类似以下的事情。例如:

aScrollView.contentSize = sizeOfImage; // Have to set a size here related to your content.
// You should set these.
aScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[aScrollView addSubview:Your Image];

aScrollView.minimumZoomScale = .5;  // You will have to set some values for these
aScrollView.maximumZoomScale = 2.0;
aScrollView.zoomScale = 1;

[self.view addSubview:aScrollView];    

答案 3 :(得分:0)

我发现了什么问题:(在我的.h文件中,带有滚动视图的IBOutlet的行已经填充了圆圈,这意味着它被连接起来。我把光标放在它上面看看哪里但没有出现我再次把它连接起来,它现在正在工作。