Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i set Image directly on UIView?

Can any body tell me how can I set Image directly on UIView ? Here is my code:

 UIView *view=[[UIView alloc]init];
 [view setImage:[UIImage imageNamed:@"image.png"]];
like image 681
Shilpa Avatar asked Oct 19 '11 05:10

Shilpa


People also ask

How do I add an image to UIImage?

With Interface Builder it's pretty easy to add and configure a UIImageView. The first step is to drag the UIImageView onto your view. Then open the UIImageView properties pane and select the image asset (assuming you have some images in your project).

How do I add an image to a view?

You can import images using the Image tool or by dragging and dropping them from Windows® Explorer. You can place images into 2D views only. Open the model view in which you want to place the image. Click Insert tab Import panel (Image).

How do I display an image in Xcode?

Drag and drop image onto Xcode's assets catalog. Or, click on a plus button at the very bottom of the Assets navigator view and then select “New Image Set”. After that, drag and drop an image into the newly create Image Set, placing it at appropriate 1x, 2x or 3x slot.


2 Answers

UIView *view=[[UIView alloc]initWithFrame:CGRectMake(x, y, width, height)];
[view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"a.png"]]];

Hope this is help you.

like image 51
Manoj Chandel Avatar answered Oct 01 '22 21:10

Manoj Chandel


This is very simple to do. Try:

UIView * view = [[UIView alloc] initWithFrame:CGRectMake(origin_x, origin_y, width, height)]; 
UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"a.png"]];
[view addSubview:imageView];
[imageView release];

You can also play with the UIImageView's frame property to move it around in your UIView. Hope that Helps!

like image 43
msgambel Avatar answered Oct 01 '22 21:10

msgambel