0207-字典、数组、延迟执行、注释

一、字典的使用

NSMutableDictionary *image1 = [NSMutableDictionary dictionary]; //新建一个字典
image1[@"icon"] = @"chiniupa";  //存储一张名叫chiniupa的照片,索引为icon
image1[@"discr"]= @"吃牛扒吧";  //存储一段”吃牛扒吧“这段文字,索引为discr

如果要提前里面的内容,用image1[@"icon"]即可提取该照片

二、数组的使用

首先要先在interface理声明

@property (nonatomic, strong) NSArray * storeData;

然后进行存储数据

- (NSArray *) storeData{
    if (_storeData == nil) {  //延时加载
    NSMutableDictionary *image1 = [NSMutableDictionary dictionary]; 
  image1[MJIconKey] = @"chiniupa"; image1[MJDescKey]= @"吃牛扒"; NSMutableDictionary *image2 = [NSMutableDictionary dictionary]; image2[MJIconKey] = @"bingli"; image2[MJDescKey]= @"兵力"; NSMutableDictionary *image3 = [NSMutableDictionary dictionary]; image3[MJIconKey] = @"wangba"; image3[MJDescKey]= @"王八"; _storeData = @[image1, image2, image3];} return _storeData; }

调用数组时

self.storeData[0];  //调用了0号位的数据

 三、添加图片

1.imageNamed方法会建立缓存

self.imageView.image = [UIImage imageNamed:image[DITI]];

2.

imageWithContentsOfFile方法不会建立缓存

NSString *filename = [NSString stringWithFormat:@"%@_%02d.jpg",name,i];
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:filename ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[images addObject:image];

 

 四、使用plist

 NSBundle *bundle = [NSBundle mainBundle];
 NSString *path = [bundle pathForResource:@"imagearry" ofType:@"plist"];
 _storeData = [NSArray arrayWithContentsOfFile:path];

 五、文档注释

/**     */

六、代码创建按钮

// 1.创建按钮
    UIButton *btn = [[UIButton alloc] init];
    
    // 2.添加按钮
    [self.view addSubview:btn];
    
    // 3.设置frame
    btn.frame = CGRectMake(50, 50, 100, 100);
    
    // 4.设置背景图片
    // 4.1.通过文件名加载图片(凡是PNG图片,都不用加拓展名)
    UIImage *normal = [UIImage imageNamed:@"btn_01"];
    // 4.2.设置普通状态下的背景图片
    [btn setBackgroundImage:normal forState:UIControlStateNormal];
    
    // 4.3.加载高亮的图片
    UIImage *high = [UIImage imageNamed:@"btn_02"];
    [btn setBackgroundImage:high forState:UIControlStateHighlighted];
    
    // 5.设置文字
    [btn setTitle:@"点我啊" forState:UIControlStateNormal];
    [btn setTitle:@"摸我干啥" forState:UIControlStateHighlighted];
    
    // 6.设置文字颜色
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
    
    // 7.监听按钮点击
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];

 七、延迟执行

 [drink addTarget:self action:@selector(runanimation) forControlEvents:UIControlEventTouchUpInside];  //在runanimation后执行

 

posted @ 2015-02-07 15:50  ilearner  阅读(167)  评论(0)    收藏  举报