超级猜图

1,模型封装,读取plist数据,并且封装成模型

-(NSArray *)questions{
    if (_questions == nil) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"questions.plist" ofType:nil];
        NSArray *arrayDict = [NSArray arrayWithContentsOfFile:path];
        NSMutableArray *arrayModel = [NSMutableArray array];
        //遍历
        for (NSDictionary *dict  in arrayDict) {
            YQLQuestion *model = [YQLQuestion questionWithDict:dict];
            [arrayModel addObject:model];
        }
        _questions = arrayModel;
    }
    return  _questions;
}

 2,判断当前btn上的标题,是否已经满了,满了的话,界面不接收点击事件

-(void)optionButtonDidClicked:(UIButton *)sender{
    //隐藏当前被点击的按钮
    sender.hidden = YES;
    //把当前被点击的文字显示到答案按钮上
    NSString *text = sender.currentTitle;
    //吧文字显示到答案按钮上
    for (UIButton *answerBtn  in self.answerView.subviews) {
        //判断每个答案按钮上的答案文字
        if (answerBtn.currentTitle == nil) {
            [answerBtn setTitle:text forState:UIControlStateNormal];
            break;
        }
    }
    BOOL isFull = YES;
    for (UIButton *btnAnswer in self.answerView.subviews) {
        if (btnAnswer.currentTitle == nil) {
            isFull = NO;
            break;
        }
    }
    //判断答案按钮是否已经满了
    if (isFull) {
        //禁止待选按钮被点击
        self.optionsView.userInteractionEnabled = NO;
    }
}

 3,设置禁用下一题按钮

//设置到达最后一题禁用下一题按钮
    self.btnNext.enabled = (self.index!= self.questions.count-1);

 4,清除所有按钮

//创建前先清除之前的按钮

    //    while (self.answerView.subviews.firstObject) {

    //        [self.answerView.subviews.firstObject removeFromSuperview];

    //    }或者用下面的方法,让数组中的每一个子对象分别调用这个方法,内部循环,无需我们自己来循环

    [self.answerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

 5,获取按钮上当前按钮的文字

 //把当前被点击的文字显示到答案按钮上
//    NSString *text = [sender titleForState:UIControlStateNormal];
    NSString *text = sender.currentTitle;

 6.每个model封装技巧

@interface YQLQuestion : NSObject
@property (nonatomic,copy) NSString *answer;
@property (nonatomic,copy) NSString *icon;
@property (nonatomic,copy) NSString *title;
@property (nonatomic,strong) NSArray *options;


-(instancetype)initWithDict:(NSDictionary *)Dict;
+(instancetype)questionWithDict:(NSDictionary *)Dict;

 

-(instancetype)initWithDict:(NSDictionary *)Dict{
    if (self = [super init]) {
        self.answer = Dict[@"answer"];
        self.icon = Dict[@"icon"];
        self.title = Dict[@"title"];
        self.options = Dict[@"options"];
    }
    return self;
}

+(instancetype)questionWithDict:(NSDictionary *)Dict{
    return  [[self alloc]initWithDict:Dict];
}

如果封装的模型里面的key与传进来的字典的key值相同,那么可以用KVC实现

[self setValueForKeysWithDictionary:dict]; 

7,修改启动图

1-直接在LaunchScreen.xib里面设置,这种是系统将xib里面的图片截图,设置成启动图。

2-工程设置里,选中项目,App Icons and Launch Images ,选中Launch images Souce ,点击Use Asset Catalog,点击Migrate,把Launch ScreenFiles删掉,在Images.xcassets里面就有了LunchImage,将做好的图片添加进去即可。

posted @ 2016-05-23 15:10  蜗牛才是大牛  阅读(177)  评论(0编辑  收藏  举报