首页 > 代码库 > 图片浏览器--UI编程
图片浏览器--UI编程
// QYViewController.h
// 图片浏览器
#import <UIKit/UIKit.h>
@interface QYViewController : UIViewController
- (IBAction)nightMode:(UISwitch *)sender;
- (IBAction)imageSizeChanged:(UISlider *)sender;
- (IBAction)setting;
- (IBAction)sliderValueChange:(UISlider *)sender;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *imageNo;
@property (weak, nonatomic) IBOutlet UILabel *imageDesc;
@property (weak, nonatomic) IBOutlet UIView *settingView;
@end
// 图片浏览器
#import <UIKit/UIKit.h>
@interface QYViewController : UIViewController
- (IBAction)nightMode:(UISwitch *)sender;
- (IBAction)imageSizeChanged:(UISlider *)sender;
- (IBAction)setting;
- (IBAction)sliderValueChange:(UISlider *)sender;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *imageNo;
@property (weak, nonatomic) IBOutlet UILabel *imageDesc;
@property (weak, nonatomic) IBOutlet UIView *settingView;
@end
// QYViewController.m
// 图片浏览器
#import "QYViewController.h"
@interface QYViewController ()
{
NSArray *_allDescs;//成员变量
}
@end
@implementation QYViewController
#pragma mark 控制器的view加载完毕后会调用一次
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//获得所有描述(通过解析plist文件来创建数组对象 必如传入文件的全路径
//如果要访问项目中资源里面的所有资源,应该用mainBundle
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"descs" ofType:@"plist"];
//加载path对应的文件来创建数组
_allDescs = [NSArray arrayWithContentsOfFile:path];
//设置默认的描述
_imageDesc.text = _allDescs[0];
}
#pragma mark夜间模式
- (IBAction)nightMode:(UISwitch *)sender {
if(sender.on){//开
self.view.backgroundColor = [UIColor darkGrayColor];
}else{//关
self.view.backgroundColor = [UIColor whiteColor];
}
}
#pragma mark 改变图片尺寸
- (IBAction)imageSizeChanged:(UISlider *)sender {
//1.取出frame
CGRect tempFrame = _imageView.bounds;
//2.修改frame
tempFrame.size.width = sender.value * 320;
tempFrame.size.height = sender.value * 100;
//3.重新赋值frame
_imageView.bounds = tempFrame;
//_imageView.transform = CGAffineTransformMakeScale(sender.value, sender.value);
}
#pragma mark 点击设置
- (IBAction)setting
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
//取出中点
CGPoint tempCenter = _settingView.center;
//修改y值
if(_settingView.frame.origin.y == self.view.frame.size.height){
tempCenter.y -= _settingView.frame.size.height;
}else{
tempCenter.y += _settingView.frame.size.height;
}
//重新赋值
_settingView.center = tempCenter;
[UIView commitAnimations];
}
- (IBAction)sliderValueChange:(UISlider *)sender {
// NSLog(@"change---:%.f",sender.value);
//获得图片名称 %.f 不保留任何小数
NSString *imageName = [NSString stringWithFormat:@"%.0f.png",sender.value];
_imageView.image = [UIImage imageNamed:imageName];
//设置序号(第几张)
_imageNo.text = [NSString stringWithFormat:@"%.0f/9",sender.value + 1];
//设置描述
int no = (int)sender.value;
_imageDesc.text = _allDescs[no];
NSLog(@"序号--%@ no--%d",_imageNo.text,no);
// NSLog(@"%@",_allDescs[(int)sender.value]);
}
@end
// 图片浏览器
#import "QYViewController.h"
@interface QYViewController ()
{
NSArray *_allDescs;//成员变量
}
@end
@implementation QYViewController
#pragma mark 控制器的view加载完毕后会调用一次
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//获得所有描述(通过解析plist文件来创建数组对象 必如传入文件的全路径
//如果要访问项目中资源里面的所有资源,应该用mainBundle
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"descs" ofType:@"plist"];
//加载path对应的文件来创建数组
_allDescs = [NSArray arrayWithContentsOfFile:path];
//设置默认的描述
_imageDesc.text = _allDescs[0];
}
#pragma mark夜间模式
- (IBAction)nightMode:(UISwitch *)sender {
if(sender.on){//开
self.view.backgroundColor = [UIColor darkGrayColor];
}else{//关
self.view.backgroundColor = [UIColor whiteColor];
}
}
#pragma mark 改变图片尺寸
- (IBAction)imageSizeChanged:(UISlider *)sender {
//1.取出frame
CGRect tempFrame = _imageView.bounds;
//2.修改frame
tempFrame.size.width = sender.value * 320;
tempFrame.size.height = sender.value * 100;
//3.重新赋值frame
_imageView.bounds = tempFrame;
//_imageView.transform = CGAffineTransformMakeScale(sender.value, sender.value);
}
#pragma mark 点击设置
- (IBAction)setting
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
//取出中点
CGPoint tempCenter = _settingView.center;
//修改y值
if(_settingView.frame.origin.y == self.view.frame.size.height){
tempCenter.y -= _settingView.frame.size.height;
}else{
tempCenter.y += _settingView.frame.size.height;
}
//重新赋值
_settingView.center = tempCenter;
[UIView commitAnimations];
}
- (IBAction)sliderValueChange:(UISlider *)sender {
// NSLog(@"change---:%.f",sender.value);
//获得图片名称 %.f 不保留任何小数
NSString *imageName = [NSString stringWithFormat:@"%.0f.png",sender.value];
_imageView.image = [UIImage imageNamed:imageName];
//设置序号(第几张)
_imageNo.text = [NSString stringWithFormat:@"%.0f/9",sender.value + 1];
//设置描述
int no = (int)sender.value;
_imageDesc.text = _allDescs[no];
NSLog(@"序号--%@ no--%d",_imageNo.text,no);
// NSLog(@"%@",_allDescs[(int)sender.value]);
}
@end
图片浏览器--UI编程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。