UI04-UIImageView图片组件
来源:互联网 发布:程序员之死 事件女方 编辑:程序博客网 时间:2024/05/17 02:32
创建一个工程,在AppDelegate.m中编写代码:
#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[selfsetWindow:[[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds]];
[self.windowmakeKeyAndVisible];
[self.windowsetRootViewController:[[ViewControlleralloc]init]];
returnYES;
}
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
[self.viewsetBackgroundColor:[UIColorwhiteColor]];
UIImageView *imageView = [[UIImageViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
[imageView setBackgroundColor:[UIColorredColor]];
[self.viewaddSubview:imageView];
#if 0
//这种方式会将图片添加到内存
[imageView setImage:[UIImage imageNamed:@"Ball.png"]];
从本地读取图片,节省内存资源
NSString *path = [[NSBundle mainBundle] pathForResource:@"Ball" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:path];
将NSdata类型转换为UIImage类型
UIImage *image = [UIImage imageWithData:imageData];
[imageView setImage:image];
设置视图填充模式
系统默认方式,将图片拉伸到全屏
imageView.contentMode = UIViewContentModeScaleToFill;
保持比例拉伸
imageView.contentMode = UIViewContentModeScaleAspectFit;
居中显示
imageView.contentMode = UIViewContentModeCenter;
#endif
//将图片组动画播放
NSMutableArray *imageArray = [NSMutableArrayarray];
for (NSInteger i =0; i <10; i++) {
UIImage *image = [UIImageimageNamed:[NSStringstringWithFormat:@"%zd", i]];
[imageArray addObject:image];
}
[imageView setAnimationImages:imageArray];
//播放间隔时间,此处为1s
[imageView setAnimationDuration:10];
//播放次数,0为无限循环
[imageView setAnimationRepeatCount:0];
//开始播放
[imageView startAnimating];
}
@end
- UI04-UIImageView图片组件
- UI04
- UI04 ViewController
- UIImageView实现图片幻灯片
- UIImageView实现图片幻灯片
- UIImageView实现图片幻灯片
- UIImageView实现图片幻灯片
- uiimageview 异步加载图片
- UIImageView实现图片幻灯片
- UIImageView 图片自适应大小
- 图片的切割-UIImageView
- UIImageView截取区域图片
- UIImageView图片动画
- UIImageView加载图片
- UIImageView绘制圆形图片
- 保存UIImageView的图片
- 图片视图UIImageView
- UIImageView处理, 图片处理
- 通讯录联系人跳转
- How Many Tables
- mysql 5.7以上版本下载及安装
- JS生成UUID的方法实例
- gnome登录界面无法登录
- UI04-UIImageView图片组件
- laravel excel 判断带 各种页面提示参数
- MOOC清华《程序设计基础》第8章:以二进制文件存储链表
- sublime插件Emmet的使用
- C# 正则表达式实现字符串搜索
- Button margin:auto 不居中
- A*搜索简介
- 【POJ 1611】 The Suspects(并查集练习)
- 2017.08.02小结