iOS复习main.storybord制作 图片浏览器 数组配合字典优化 UIImageView播放动画
2016-06-07 11:58
555 查看
#import "ViewController.h"
@interface
ViewController (){
NSMutableDictionary *imageDict;
NSMutableArray *dataArray;
}
@property (weak,nonatomic)IBOutletUIImageView
*image;
@property (weak,nonatomic)IBOutletUILabel
*describe;
@property (weak,nonatomic)IBOutletUIButton
*leftBtn;
@property (weak,nonatomic)IBOutletUIButton
*rightBtn;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
NSArray *descText = [@"鲜花美酒,猫咪,圣诞快乐,卡通美女"componentsSeparatedByString:@","];
NSLog(@"%@",descText);
dataArray = [NSMutableArrayarray];
for (int i =0; i < descText.count;
i++) {
imageDict = [NSMutableDictionarydictionary];
UIImage *iimage = [UIImageimageNamed:[NSStringstringWithFormat:@"%d.jpg",i+1]];
imageDict[@"image"] = iimage;
imageDict[@"icon"] = descText[i];
NSLog(@"imageDict%d:%@",i,imageDict);
// dataArray[i] = imageDict;
[dataArrayaddObject:imageDict];
}
NSLog(@"dataArray:%@",dataArray);
[selfbundle];
[selfplist];
}
static int i =1;
- (IBAction)clickedBtn:(UIButton *)sender {
NSLog(@"i = %d",i);
sender.enabled =YES;
if (i >=0 &&i<4
) {
imageDict =dataArray[i];
NSLog(@"imagDict %@",imageDict);
_describe.text =imageDict[@"icon"];
_image.image =imageDict[@"image"];
}
if (sender.tag ==0) {
_rightBtn.enabled =YES;
if (i ==0) {
sender.enabled =NO;
i =0;
}else{
i--;
sender.enabled =YES;
}
}elseif (sender.tag ==1){
_leftBtn.enabled =YES;
if (i ==3) {
sender.enabled =NO;
i =3;
}else{
i++;
sender.enabled =YES;
}
}
}
-(void)plist{
NSBundle *bundle = [NSBundlemainBundle];
//读取字典
NSString *path = [bundlepathForResource:@"myPlist.plist"ofType:nil];
NSDictionary *dictJG = [NSDictionarydictionaryWithContentsOfFile:path];
NSLog(@"dictJG %@",dictJG);
//读取数组
NSString *pathArr = [bundlepathForResource:@"myList.plist"ofType:nil];
NSArray *array = [NSArrayarrayWithContentsOfFile:pathArr];
NSLog(@"array %@",array);
}
#pragma mark -NSBudle 文件下读取图片
-(void)bundle{
//在bundle文件夹中读取图片
NSLog(@"沙盒路径:%@",NSHomeDirectory());
NSBundle *bundle = [NSBundlemainBundle];
//拼接文件路径
// NSString *path = [bundle pathForResource:@"android-themes-blue" ofType:@".png"];
NSString *path = [bundlepathForResource:@"android-themes-blue.png"ofType:nil];
_imageView.image = [UIImageimageWithContentsOfFile:path];
}
@end
UIImageView播放动画
- (IBAction)action:(id)sender {
if (_imageView.isAnimating)
return; //判断动画是否正在运行
//加载图片
NSMutableArray *imageArr = [NSMutableArray
array];
for (int i =
0; i<10; i++) {
NSString *imageName = [NSString
stringWithFormat:@"a_%d0.png",i];
// UIImage *image = [UIImage imageNamed:imageName];
//用NSBundle,优化内存
NSString *path = [[NSBundle
mainBundle] pathForResource:imageName
ofType:nil];
UIImage *image = [UIImage
imageWithContentsOfFile:path];
[imageArr addObject:image];
}
_imageView.animationImages = imageArr;
//设置动画属性
_imageView.animationDuration =
2;
_imageView.animationRepeatCount =
5;
[_imageView
startAnimating];
//开始动画
}
@interface
ViewController (){
NSMutableDictionary *imageDict;
NSMutableArray *dataArray;
}
@property (weak,nonatomic)IBOutletUIImageView
*image;
@property (weak,nonatomic)IBOutletUILabel
*describe;
@property (weak,nonatomic)IBOutletUIButton
*leftBtn;
@property (weak,nonatomic)IBOutletUIButton
*rightBtn;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
NSArray *descText = [@"鲜花美酒,猫咪,圣诞快乐,卡通美女"componentsSeparatedByString:@","];
NSLog(@"%@",descText);
dataArray = [NSMutableArrayarray];
for (int i =0; i < descText.count;
i++) {
imageDict = [NSMutableDictionarydictionary];
UIImage *iimage = [UIImageimageNamed:[NSStringstringWithFormat:@"%d.jpg",i+1]];
imageDict[@"image"] = iimage;
imageDict[@"icon"] = descText[i];
NSLog(@"imageDict%d:%@",i,imageDict);
// dataArray[i] = imageDict;
[dataArrayaddObject:imageDict];
}
NSLog(@"dataArray:%@",dataArray);
[selfbundle];
[selfplist];
}
static int i =1;
- (IBAction)clickedBtn:(UIButton *)sender {
NSLog(@"i = %d",i);
sender.enabled =YES;
if (i >=0 &&i<4
) {
imageDict =dataArray[i];
NSLog(@"imagDict %@",imageDict);
_describe.text =imageDict[@"icon"];
_image.image =imageDict[@"image"];
}
if (sender.tag ==0) {
_rightBtn.enabled =YES;
if (i ==0) {
sender.enabled =NO;
i =0;
}else{
i--;
sender.enabled =YES;
}
}elseif (sender.tag ==1){
_leftBtn.enabled =YES;
if (i ==3) {
sender.enabled =NO;
i =3;
}else{
i++;
sender.enabled =YES;
}
}
}
-(void)plist{
NSBundle *bundle = [NSBundlemainBundle];
//读取字典
NSString *path = [bundlepathForResource:@"myPlist.plist"ofType:nil];
NSDictionary *dictJG = [NSDictionarydictionaryWithContentsOfFile:path];
NSLog(@"dictJG %@",dictJG);
//读取数组
NSString *pathArr = [bundlepathForResource:@"myList.plist"ofType:nil];
NSArray *array = [NSArrayarrayWithContentsOfFile:pathArr];
NSLog(@"array %@",array);
}
#pragma mark -NSBudle 文件下读取图片
-(void)bundle{
//在bundle文件夹中读取图片
NSLog(@"沙盒路径:%@",NSHomeDirectory());
NSBundle *bundle = [NSBundlemainBundle];
//拼接文件路径
// NSString *path = [bundle pathForResource:@"android-themes-blue" ofType:@".png"];
NSString *path = [bundlepathForResource:@"android-themes-blue.png"ofType:nil];
_imageView.image = [UIImageimageWithContentsOfFile:path];
}
@end
UIImageView播放动画
- (IBAction)action:(id)sender {
if (_imageView.isAnimating)
return; //判断动画是否正在运行
//加载图片
NSMutableArray *imageArr = [NSMutableArray
array];
for (int i =
0; i<10; i++) {
NSString *imageName = [NSString
stringWithFormat:@"a_%d0.png",i];
// UIImage *image = [UIImage imageNamed:imageName];
//用NSBundle,优化内存
NSString *path = [[NSBundle
mainBundle] pathForResource:imageName
ofType:nil];
UIImage *image = [UIImage
imageWithContentsOfFile:path];
[imageArr addObject:image];
}
_imageView.animationImages = imageArr;
//设置动画属性
_imageView.animationDuration =
2;
_imageView.animationRepeatCount =
5;
[_imageView
startAnimating];
//开始动画
}
相关文章推荐
- Android界面效果UI开发资料汇总(附资料包)
- python3使用tkinter实现ui界面简单实例
- pyside写ui界面入门示例
- 全向移动平台android版手机控制器——UI界面设计
- 如何为PreferenceScreen分别设置窗口背景图片和actionBar背景图片/拖动时不黑屏
- U3d屏幕自适应
- QT按钮的四种样式
- Windows系统中的颜色枚举
- iOS复习main.storybord制作 计算器与运动色块
- ios复习main.storybord制作 按钮控制图片运动与变大缩小旋转
- 2014-1-27codeview
- Android中UI界面控制方式介绍与使用
- MindFusion.Charting for WPFv1.9发布,高性能图表控件【附下载】
- 疯狂ios讲义之代码控制UI界面 推荐
- 国际象棋模拟
- OC学习日记017(二)从网络下载图片放到UI界面
- QT5中的UI界面 控件随窗口自适应变化大小 无需写任何代码!
- iOS 提示框,为什么你应该使用 MBProgressHUD?
- Masonry的简单使用
- EAIntroView–高度可定制的iOS应用欢迎页通用解决方案