#import "AppDelegate.h"
@interface AppDelegate ()
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
[_window setBackgroundColor:[UIColor whiteColor]];
//==============UIImageView=================
//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