IOS学习—控件的综合练习
来源: 阅读:1273 次 日期:2015-04-21 13:49:01
温馨提示: 小编为您整理了“IOS学习—控件的综合练习”,方便广大网友查阅!

//

// ViewController.h

// 图片浏览器

//

// Created by on 15/4/14.

// Copyright (c) 2015年 apple. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (weak, nonatomic) IBOutlet UILabel *imageValue;

@property (weak, nonatomic) IBOutlet UILabel *imageDesc;

@property (weak, nonatomic) IBOutlet UIView *settingView;

- (IBAction)valueChange:(UISlider *)sender;

- (IBAction)settingButton;

- (IBAction)darkModel:(UISwitch *)sender;

- (IBAction)imageSize:(UISlider *)sender;

@end

//

// ViewController.m

// 图片浏览器

//

// Created by on 15/4/14.

// Copyright (c) 2015年 apple. All rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

{

NSArray *_imageMess;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// 要访问项目中的所有资源用mainBundle

NSBundle *bundle = [NSBundle mainBundle];

NSString *filePath = [bundle pathForResource:@"imageMessages" ofType:@"plist"];

// 读取文件要传入绝对路径

_imageMess = [NSArray arrayWithContentsOfFile:filePath];

NSDictionary *dic = _imageMess[0];

NSString *imageName = [dic objectForKey:@"icon"];

_imageView.image = [UIImage imageNamed:imageName];

NSString *imageMessage = [dic objectForKey:@"title"];

_imageDesc.text = imageMessage;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (IBAction)valueChange:(UISlider *)sender {

// 这里的%.f即为不保留小数位,四舍五入

// NSString *imageName = [NSString stringWithFormat:@"%.f", sender.value];

NSDictionary *dic = _imageMess[(int)sender.value - 1];

NSString *imageName = [dic objectForKey:@"icon"];

_imageView.image = [UIImage imageNamed:imageName];

NSString *imageValue = [NSString stringWithFormat:@"%.f/%.f", sender.value, sender.maximumValue];

_imageValue.text = imageValue;

NSString *imageMessage = [dic objectForKey:@"title"];

_imageDesc.text = imageMessage;

}

#pragma mark 注意这里的写法,如果信息处理不同的话,多用这种方式重构代码

-(void)animationCustom:(void (^)())block {

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.35];

block();

[UIView commitAnimations];

}

- (IBAction)settingButton {

CGFloat viewHeight = _settingView.frame.size.height;

[self animationCustom:^{

if (_settingView.frame.origin.y == self.view.frame.size.height) {

CGRect frame = _settingView.frame;

frame.origin.y -= viewHeight;

_settingView.frame = frame;

} else {

CGRect frame = _settingView.frame;

frame.origin.y += viewHeight;

_settingView.frame = frame;

}

}];

}

- (IBAction)darkModel:(UISwitch *)sender {

if (sender.on) {

self.view.backgroundColor = [UIColor darkGrayColor];

} else {

self.view.backgroundColor = [UIColor whiteColor];

}

}

- (IBAction)imageSize:(UISlider *)sender {

_imageView.transform = CGAffineTransformMakeScale(sender.value, sender.value);

}

@end

更多信息请查看IT技术专栏

更多信息请查看技术文章
手机网站地址:IOS学习—控件的综合练习
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!

2025国考·省考课程试听报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:
咨询QQ:526150442(9:00—18:00)版权所有:
云南网警报警专用图标
Baidu
map