iOS学习之NSBundle介绍和使用

时间:2023-03-09 15:28:27
iOS学习之NSBundle介绍和使用

iOS学习之NSBundle介绍和使用

http://blog.csdn.net/totogo2010/article/details/7672271

新建一个Single View Application,并在加入viewDidLoad方法里加入如下代码:

  1. //    通过使用下面的方法得到程序的main bundle
  2. NSBundle *mainBundle = [NSBundle mainBundle];
  3. NSString *imagePath = [mainBundle pathForResource:@"QQ20120616-1" ofType:@"png"];
  4. NSLog(@"%@", imagePath);
  5. UIImage *image = [[UIImage alloc]initWithContentsOfFile:imagePath];
  6. UIImageView  *imageView = [[UIImageView alloc] initWithImage:image];
  7. [self.view addSubview:imageView];