UIImageView的属性与方法

来源:互联网 发布:祝利荣牛熊线指标源码 编辑:程序博客网 时间:2024/05/16 19:09

  bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 对应bundle,cocoa提供了类NSBundle.我们的程序是一个bundle. 在Finder中,一个应用程序看上去和其他文件没有什么区别. 但是实际上它是一个包含了nib文件,编译代码,以及其他资源的目录. 我们把这个目录叫做程序的main bundle。


获取图片

  1.   NSString *path = [[NSBuddle mainBuddle] pathForResource:@"resourceName" oftype@"resourceType"];

       UIImage *image = [UIImage imageWithContentsOfFile:path]
];   //使用缓存,一般用小图片

  2.   UIImage *image = [UIImage imageNamed:@"imageName"];


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    self.window = [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];

    iv = [[UIImageViewalloc]initWithFrame:CGRectMake(30,100, 62,74)];

    //uiimage 直接使用类的方法UIImage imageNamed用到了缓存

  

    // UIImage * ig = [UIImage imageNamed:@"nc.png"];

    self.window.backgroundColor=[UIColorwhiteColor];

    //得到图片nc.png的路径

    NSString *path = [[NSBundlemainBundle]pathForResource:@"nc"ofType:@"png"];

   

    //UIImage imageWithContentsOfFile从路径中得到图片传给ig

    ig = [UIImageimageWithContentsOfFile:path];

    NSLog(@"%@",path);

    //image挂在imageview

    [ivsetImage:ig];

    

    UIButton * but = [[UIButtonalloc]initWithFrame:CGRectMake(130,110, 50,40)];

    

    [but setTitle:@"转换"forState:UIControlStateNormal];

    

    but.backgroundColor=[UIColorblueColor];

    [but addTarget:selfaction:@selector(ac)forControlEvents:UIControlEventTouchUpInside];

    [self.windowaddSubview:but];

    [self.windowaddSubview:iv];

    [self.windowmakeKeyAndVisible];

    returnYES;

}


-(void)ac

{

    if (flag==NO) {

        ig=[UIImageimageNamed:@"nc.png"];

        [ivsetImage:ig];

        flag=YES;

    }

    else

    {

        ig=[UIImageimageNamed:@"zd.png"];

        [ivsetImage:ig]; 

        flag=NO;

    }

}


0 0