-1

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

I have written following code in viewDidLoad method.

- (void)viewDidLoad {

    [super viewDidLoad];
    UIImageView *dot = [[UIImageView alloc] initWithFrame:CGRectMake(30,30,30,50)];
    dot.image = [UIImage imageNamed:@"personal_info.png"];
    [self.view addSubview:dot];
}
Matt
  • 14,906
  • 27
  • 99
  • 149
CodeGuru
  • 61
  • 8
  • ok , what happens next ? – Teja Nandamuri May 02 '16 at 13:51
  • 1
    What exactly you want. With above you should get UIImagaeView on your View. If you are not seeing ImageView then check your resource `personal_info.png` present or not ? – Bhumeshwer katre May 02 '16 at 14:02
  • try `[self.view bringSubviewToFront:dot];` just to make sure it isn't covered by another object on screen – MSU_Bulldog May 02 '16 at 14:06
  • I added this line of code also ([self.view bringSubviewToFront:dot];) – CodeGuru May 03 '16 at 07:04
  • I added this line of code also ([self.view bringSubviewToFront:dot];) but still i cannot see the imageview and image is also present in the supporting files. I am having a xib file linked to this viewcontroller, what should i do? – CodeGuru May 03 '16 at 07:06

1 Answers1

0

please check that image name is correct, case sensitivity issues can cause this. If that not the case, please put a break point in viewwillAppear method and check the ui hierarchy using view debugger. please go through this link to know about view debugger. make sure that the image view you have added is present in view hierarchy. Hope this will help you.

Aneesh
  • 107
  • 7