![](/img/trans.png)
[英]How to add a UIImageView of specific size programmatically in objective-c. I also have a xib file for the same class but i donot want to use it
[英]How to change UiImageView in xib file programmatically
我試圖在xib文件中更改UIImageView
,但似乎不起作用。我有帶有UIImageView
xib文件。 我將UIImageView
鏈接到我的xib文件。在我的主ViewController
我調用了一個將更改xib文件中的UIImageView
的函數。以下是我用於更改xib文件中的圖像的函數
UIView *view = [[[NSBundle bundleForClass:[self class]]loadNibNamed:@"View" owner:self options:nil] firstObject];
[self addSubview:view];
view.frame = self.bounds;
_imageTest.image = [UIImage imageNamed:@"0.png"];
我做錯什么了嗎。 我在堆棧溢出中搜索,但似乎找不到我想要的東西。
我不確定您是否要嘗試使用其他UI<control
更改UIImageView
的圖像或控件本身。
要更改UIImage
,只需在viewController類中需要一個插座,然后將圖像設置為它即可。 如:
[self.yourImageView setImage:[UIImage imageNamed:@"0.png"]]; //and make sure the 0.png file exist in the application bundle.
如果您有興趣更改控件本身,那么最好不要也創建UIImage。 在運行時創建UIImage和其他控件,然后將控件添加到視圖中。
嘗試像這樣加載您的xib視圖:
UIView *view = [[[NSBundle mainBundle] loadNibNamed:@"yourView" owner:self options:nil] objectAtIndex:0];
並在設置圖像的位置放置斷點,請確保_imageTest不為零。
沒關系的 我可以使它工作了。 看來我的UIImageView問題。 在我刪除並添加回所有東西后已經工作了。 謝謝你們的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.