IOS开发之UIImageView


#import "AppDelegate.h"app


@interface AppDelegate ()ide


@end ui


@implementation AppDelegatethis



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

    // Override point for customization after application launch..net

   

    

     _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];3d

    

    [_window setBackgroundColor:[UIColor whiteColor]];rest

    

    //==============UIImageView=================orm

    //UIImageView:UIView UIView的全部属性方法UIImageView都拥有对象

    //UIImageView专门用来显示图片的控件

    //1.建立一个UIImageView对象

    UIImageView *imageView = [[UIImageView alloc]

                              initWithFrame:CGRectMake(50, 50, 200, 200)];

    //2.设置背景颜色

    imageView.backgroundColor = [UIColor cyanColor];

    

    //3.显示在界面上;

    [_window addSubview:imageView];

    

       //UIIamge图片类

    //根据图片名建立图片(前提是图片已经添加到工程中)

    //拖到工程中的图片实质是在当前这个应用程序的安装包里面;

    //参数:图片的名字(若是图片是png图片,图片的后缀名能够省略,其余图片后缀必须加上);

    UIImage *image1 = [UIImage imageNamed:@"back2.jpg"];

    

    //根据文件路径来建立图片;

    //参数是图片文件的路径;拿到包中图片的路径;(能够拿到当前工程中任何文件的路径)

    //参数一:文件的名字

    //参数二:文件的后缀

    NSString *path = [[NSBundle mainBundle] pathForResource:

                      @"player_down_1"  ofType:@"png"];

    UIImage *image2 = [UIImage imageWithContentsOfFile:path];

    

    //==========获取图片的大小==============

    CGSize imageSize =  image1.size;

   

    //NSLog(@"%@",NSStringFromCGSize(imageSize));

    

    //两种建立图片方式的区别:

    //1.经过图片名直接建立:代码简单,imageNamed建立的图片的声明语法是整个工程结束,

    //并且若是是同一张图片建立的image对象是惟一的.

    //2.经过图片文件的路径来建立图片

    

    //4.设置图片(核心属性)

    [imageView setImage:image1];

    

    //5.设置内容模式

//    typedef NS_ENUM(NSInteger, UIViewContentMode) {

//        UIViewContentModeScaleToFill,

//(默认的模式:将图片进行缩放将图片整个显示在imageView;

//        UIViewContentModeScaleAspectFit,//将图片按照比例缩放完整显示在imageView

//        UIViewContentModeScaleAspectFill,//图片和imageView都按图片的比例缩放

//        UIViewContentModeRedraw,

//        UIViewContentModeCenter,//完整的将图片中间的显示出来

//        UIViewContentModeTop,

//        UIViewContentModeBottom,

//        UIViewContentModeLeft,

//        UIViewContentModeRight,

//        UIViewContentModeTopLeft,

//        UIViewContentModeTopRight,

//        UIViewContentModeBottomLeft,

//        UIViewContentModeBottomRight,

//    };

    

    [imageView setContentMode:UIViewContentModeScaleToFill];

    

    [_window makeKeyAndVisible];

    


    

    

    

    return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}


- (void)applicationWillTerminate:(UIApplication *)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}


@end

相关文章
相关标签/搜索