2012-07-23 168 views
0

我想通過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]; 

我在做什麼錯?

回答

0

我發現了什麼是錯誤的:(在我的.h文件,用滾動視圖的IBOutlet中的線有圓填寫,這意味着它是迷上了我把光標放在它看到哪裏沒有任何東西顯示出來,我再次掛鉤,現在正在工作

2

我敢肯定你的意思

[UIImage imageNamed:@"button.png"] 

;-)

+0

我沒有把擴展名放到button.png或[email protected]。 – pedroremedios 2012-07-23 20:24:47

+0

我試過了button.png – pedroremedios 2012-07-23 20:34:30

+0

@pedroremedios你試過把它加到非滾動視圖嗎? – 2012-07-23 20:57:21

0

我的想法: - 確保該文件的確是在編譯資源。 - 通過NSLog檢查圖像是否加載正確,打印圖像的CGSize。 - 可以肯定的是,幀正在設置正確

你儘可以調用[UIImage的imageNamed:@「按鈕」],它看起來正確的視網膜或沒有圖像根據設備的

0

滾動型需要你設置一些屬性。特別是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];