文档章节

UI代码练习-UIView的ContentMode

TomatosX
 TomatosX
发布于 2015/01/07 11:40
字数 831
阅读 27
收藏 0
//
//  AppDelegate.m
//  UIView的ContentMode
//
//  Created by on 14-12-23.
//  Copyright (c) 2014年 apple. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//    self.window.windowLevel = UIWindowLevelStatusBar;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    UIImageView *image1 = [[UIImageView alloc] initWithFrame:CGRectMake(320/2 - 300/2.0, 50, 300, 200)];
//    UIViewContentModeScaleAspectFit,设置图片大小为适应
//    UIViewContentModeScaleToFill,默认的情况,填充
//    UIViewContentModeScaleAspectFill,拉伸
    image1.contentMode = UIViewContentModeScaleAspectFit;
    image1.backgroundColor = [UIColor redColor];
    
//    如果这里图片格式为png,那么imageNamed直接写成01即可
//    如果图片是Retina格式,名称为2@2x.png,那么写成2即可,不用在加上@2x
    image1.image = [UIImage imageNamed:@"01.jpg"];
    [self.window addSubview:image1];
    
    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:.
    // Saves changes in the application's managed object context before the application terminates.
    [self saveContext];
}

#pragma mark - Core Data stack

@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

- (NSURL *)applicationDocumentsDirectory {
    // The directory the application uses to store the Core Data store file. This code uses a directory named "apple.UIView_ContentMode" in the application's documents directory.
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}

- (NSManagedObjectModel *)managedObjectModel {
    // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model.
    if (_managedObjectModel != nil) {
        return _managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"UIView_ContentMode" withExtension:@"momd"];
    _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return _managedObjectModel;
}

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
    // The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it.
    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }
    
    // Create the coordinator and store
    
    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"UIView_ContentMode.sqlite"];
    NSError *error = nil;
    NSString *failureReason = @"There was an error creating or loading the application's saved data.";
    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
        // Report any error we got.
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";
        dict[NSLocalizedFailureReasonErrorKey] = failureReason;
        dict[NSUnderlyingErrorKey] = error;
        error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
        // Replace this with code to handle the error appropriately.
        // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }
    
    return _persistentStoreCoordinator;
}


- (NSManagedObjectContext *)managedObjectContext {
    // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
    if (_managedObjectContext != nil) {
        return _managedObjectContext;
    }
    
    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (!coordinator) {
        return nil;
    }
    _managedObjectContext = [[NSManagedObjectContext alloc] init];
    [_managedObjectContext setPersistentStoreCoordinator:coordinator];
    return _managedObjectContext;
}

#pragma mark - Core Data Saving support

- (void)saveContext {
    NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
    if (managedObjectContext != nil) {
        NSError *error = nil;
        if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
            // Replace this implementation with code to handle the error appropriately.
            // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        }
    }
}

@end



© 著作权归作者所有

TomatosX
粉丝 22
博文 207
码字总数 119547
作品 0
成都
iOS工程师
私信 提问
iOS开发——UIImageView的contentMode、裁剪和layer属性详解

版权声明:本文为博主原创文章,欢迎分享到其它技术社区,分享请标明出处: https://blog.csdn.net/CHENYUFENG1991/article/details/51814220 在我们iOS开发过程中,UIImageView是一个非常常...

乞力马扎罗的雪CYF
2016/07/03
0
0
iOS UIView contentMode

输入链接说明 Content Modes contentMode是UIView的属性,这个属性的值决定了,当视图的几何形状变化时如何复用它的内容。当视图第一次展示前,它会将自己的内容渲染成一张底层的bitmap. 然后...

tianhongyu
2016/08/05
1
1
图像缩放工具--MMScalableVectorView

MMScalableVectorView 是一款把静态的 PaintCode 或者 Qwarkee 代码变成 UIView,优化 contentMode 属性,使它能完全缩放的工具。...

叶秀兰
2013/12/23
156
0
[iOS Animation]-CALayer 显示方式

寄宿图 图片胜过千言万语,界面抵得上千图片 ——Ben Shneiderman 我们在第一章『图层树』中介绍了CALayer类并创建了一个简单的有蓝色背景的图层。背景颜色还好啦,但是如果它仅仅是展现了一...

浩浩老师
2015/09/30
37
0
ScollView pageView

#import "ViewController.h" #define ImageCount 10 #define SCREENWIDTH [UIScreen mainScreen].bounds.size.width #define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height @inter......

TimeConcept
2015/12/18
26
0

没有更多内容

加载失败,请刷新页面

加载更多

跟我来见证:《Kafka如何实现每秒上百万的高并发写入?》

本文来聊一下Kafka的一些架构设计原理,这也是互联网公司面试时非常高频的技术考点。 Kafka是高吞吐低延迟的高并发、高性能的消息中间件,在大数据领域有极为广泛的运用。配置良好的Kafka集群...

Java干货分享
24分钟前
3
0
Storm+Hbase广告实时统计

本文主要讲述使用Kafka+Strom+Hbase搭建的一套广告实时计算系统。其中服务器显示使用的是SpringBoot+Vue+ElementUI+EChats. 主要内容: 1.需求 2.日志格式 3.Hbase表格设计 4.编写Storm程序 ...

飓风2000
46分钟前
4
0
android,ContentProvider+ContentObserver+ContentResolver,用法。

这个是传智播客老师讲android开发时的一个图。 一、 PersonProvider继承ContentProvider,实现ContentProvider中的数据操作类。 ContentObserver——内容观察者,目的是观察(捕捉)特定Uri引起...

天王盖地虎626
52分钟前
3
0
解决markdown中的不换行问题

没有解决我的格式显示问题 https://blog.csdn.net/qq_23483671/article/details/79017609

南桥北木
57分钟前
2
0
产品上新|ZStack3.5.0正式发布啦!

海量产品资料传送门~ 一、ZStack全线产品下载通道汇总 社区版(免费): https://www.zstack.io/product/zstack_open_source/ 企业版下载: https://www.zstack.io/product/zstack_enterpris...

ZStack社区版
59分钟前
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部