项目结构
视图分析
加载plist数据
将数据的初始化放在了数据模型里
JKQuestionInfo
+ (NSArray *)questions{
NSString *path = [[NSBundle mainBundle]pathForResource:@"questions" ofType:@"plist"];
NSArray *array = [NSArray arrayWithContentsOfFile:path];
NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:array.count];
for (NSDictionary *dict in array) {
[arrayM addObject:[self questionWithDict:dict]];
}
return [arrayM copy];
}
ViewController
- (NSArray *)questions {
if (nil == _questions) {
_questions = [JKQuestionInfo questions];
}
return _questions;
}
ViewController
定义常量
//需要计算的话,用宏,否则用const,如下
//图片按钮的宽度
#define imgW self.imgInsideBtn.bounds.size.width
//答案按钮宽
CGFloat const kBtnW = 35;
UIButton 配置
//为按钮设置背景图片
[self.imgInsideBtn setImage:question.image forState:UIControlStateNormal];
//设定按钮高亮下的背景图片
[btn setBackgroundImage:[UIImage imageNamed:@"btn_answer_highlighted"] forState:UIControlStateHighlighted];
//设定按钮常规下的字体颜色
[btn setTitleColor:kAnswerBtnTitleColor forState:UIControlStateNormal];
//设定按钮的点击方法
[btn addTarget:self action:@selector(answerBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
//设定按钮上的字符
[answerBtn setTitle:nil forState:UIControlStateNormal];
//alpha值切换按钮的不同状态
self.cover.alpha = 0.0;
遍历移除所有子视图
for (UIButton *btn in self.answerView.subviews) {
[btn removeFromSuperview];
}
UIView 配置
//该按钮不隐藏
optionBtn.hidden = NO;
//该view是否具有互动性
self.optionsView.userInteractionEnabled = YES;
//将中间图片按钮设置成是离屏幕最近一层,所有子视图的最上面
[self.view bringSubviewToFront:self.imgInsideBtn];