Reputation: 31
I created an UIView. I need to set a small image on a particular position.
I can do it setting the image in a small separate view. But, I plan to do it dynamically on a Large UIView which is full screen. Thanks.
Upvotes: 0
Views: 558
Reputation: 910
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,200)];
view.backgroundColor=[UIColor clearColor];
[self.view addSubview:view];
// add image in view
UIImageView *imageView =[[UIImageView alloc] initWithFrame:CGRectMake(50,50,20,20)];
imageView.image=[UIImage imageNamed:@"image.png"];
[view addSubview:imageView];
Upvotes: 3
Reputation: 8782
Try this code.
UIImage *image = [UIImage imageNamed:@"imagename.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
//specify the frame of the imageView in the superview , here it will fill the superview
imageView.frame = catView.bounds;
// set custom frame as per your requirement
//or
// imageView.frame = CGRectMake(10,10,30,30);
//or
//according to superviews frame
//imageView.frame=CGRectMake(10,10,yourUIViewObject.bounds.size.width/2,yourUIViewObject.bounds.size.height/2);
// add the imageview to the superview
[yourUIViewObject addSubview:imageView];
Upvotes: 0
Reputation: 48514
That is what views are for: manipulating UI widgets.
By far, your best approach is to position a UIImageView
.
You can also override the view drawing methods:
override func drawRect(rect: CGRect) {
// Curstom
}
Upvotes: 0