Addsubview not showing uiimageview
问题描述:
我想通过addsubiew在scrollview上放置一个uiimageview,但没有显示。这是viewDidLoad中的代码:Addsubview not showing uiimageview
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];
我在做什么错?
答
我发现了什么是错误的:(在我的.h文件,用滚动视图的IBOutlet中的线有圆填写,这意味着它是迷上了我把光标放在它看到哪里没有任何东西显示出来,我再次挂钩,现在正在工作
答
我敢肯定你的意思
[UIImage imageNamed:@"button.png"]
;-)
答
我的想法: - 确保该文件的确是在编译资源。 - 通过NSLog检查图像是否加载正确,打印图像的CGSize。 - 可以肯定的是,帧正在设置正确
你尽可以调用[UIImage的imageNamed:@“按钮”],它看起来正确的视网膜或没有图像根据设备的
答
滚动型需要你设置一些属性。特别是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];
我没有把扩展名放到button.png或[email protected]。 – pedroremedios 2012-07-23 20:24:47
我试过了button.png – pedroremedios 2012-07-23 20:34:30
@pedroremedios你试过把它加到非滚动视图吗? – 2012-07-23 20:57:21