Create UIImageView

How to create UIImageView code in code instead of creating it in my xib file?

+6
source share
4 answers
 UIImageView *someImageView = [[UIImageView alloc] initWithFrame:someRect]; someImageView.image = someImage; [self.view addSubview:someImageView]; 

Easy as a pie !: D

You might also want to check out Apple docs: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImageView_Class/Reference/Reference.html

+8
source

You can create a separate UIImage and create your UIImageView from your UIImage.

 UIImage *myImage = [UIImage imageNamed:@"great_pic.png"]; UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage]; 

Then set the size of your UIImageView

 [myImageView setFrame:CGRectMake(0, 0, 100, 200)]; 

Do whatever you want with your image, but don't forget to release it.

 [anotherView addSubview:myImageView]; [myImageView release]; 
+19
source

The answers are still more complicated than they should be: initWithImage: "adjusts the receiver frame to fit the size of the specified image." So all you need is

 UIImageView* v = [[UIImageView alloc] initWithImage: someImage]; 
+4
source
 UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 7, 190, 23]; tabNameBackGround.image = [UIImage imageNamed:@"a.png"]; [self.view addSubview:imageView]; 
+3
source

Source: https://habr.com/ru/post/900054/


All Articles