<pre name="code" class="objc" style="color: rgb(207, 135, 36); font-size: 20px;">// ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *pageLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imgView;
- (IBAction)changeSliderValue:(UISlider *)sender;
- (IBAction)setBtn:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIView *View2;
- (IBAction)clickSwitch:(UISwitch *)sender;
@property (weak, nonatomic) IBOutlet UIView *View3;
@property (weak, nonatomic) IBOutlet UILabel *labeltShow;
- (IBAction)showMessage:(UIButton *)sender;
- (IBAction)changeSize:(UISlider *)sender;
@end
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 20px; font-family: Menlo; color: rgb(207, 135, 36);"><pre name="code" class="objc">// ViewController.m
#import "ViewController.h"
@interface ViewController ()
@property NSMutableArray *ary;
@property NSMutableArray *ary1;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_ary = [NSMutableArray array];
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"starInfo" ofType:@"plist"];
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:path];
_ary = [dic objectForKey:@"title"];
NSString *path2 = [bundle pathForResource:@"starInfo" ofType:@"plist"];
NSMutableDictionary *dic2 = [NSMutableDictionary dictionaryWithContentsOfFile:path2];
_ary1 = [dic2 objectForKey:@"message"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark 改变星座图片
//获得图片以及滑动图片
- (IBAction)changeSliderValue:(UISlider *)sender {
NSString *imgStr = [NSString stringWithFormat:@"star%.0f.jpg",sender.value];
_imgView.image = [UIImage imageNamed:imgStr];
_pageLabel.text = [NSString stringWithFormat:@"%.0f/12",sender.value];
NSLog(@"%@",_pageLabel.text);
int num = (int)(sender.value+0.5);
NSString *str = [_ary objectAtIndex:num-1];
NSString *str1 = [_ary1 objectAtIndex:num-1];
_titleLabel.text = str;
_labeltShow.text = str1;
}
#pragma mark 点击设置按钮
//点击设置按钮调整信息
- (IBAction)setBtn:(UIButton *)sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
//判断详情的View3是否出来,出来的话给他返回去
CGRect frameNew = _View3.frame;
if (frameNew.origin.y<568) {
frameNew.origin.y +=_View3.frame.size.height;
_View3.frame = frameNew;
}
//设置框的展示
CGRect frame = _View2.frame;
if (frame.origin.y>560) {
frame.origin.y -=_View2.frame.size.height;
}else{
frame.origin.y +=_View2.frame.size.height;
}
_View2.frame = frame;
[UIView commitAnimations];
}
#pragma mark 设置按钮内部操作设置
//点击夜间模式
- (IBAction)clickSwitch:(UISwitch *)sender {
if (sender.on) {
self.view.backgroundColor = [UIColor blackColor];
_titleLabel.textColor = [UIColor whiteColor];
_pageLabel.textColor = [UIColor whiteColor];
}
else
{
self.view.backgroundColor = [UIColor brownColor];
_titleLabel.textColor = [UIColor blackColor];
_pageLabel.textColor = [UIColor blackColor];
}
}
//改变图片大小
- (IBAction)changeSize:(UISlider *)sender {
CGAffineTransform trans = _imgView.transform;
trans = CGAffineTransformMakeScale(sender.value, sender.value);
_imgView.transform = trans;
}
#pragma mark 详情按钮
//点击详细信息
- (IBAction)showMessage:(UIButton *)sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
//详情信息框的展示
CGRect frame = _View3.frame;
if (frame.origin.y>560) {
frame.origin.y -= _View3.frame.size.height;
}else{
frame.origin.y += _View3.frame.size.height;
}
_View3.frame = frame;
if (_View2.frame.origin.y<568) {
CGRect frameOld = _View2.frame;
frameOld.origin.y += _View2.frame.size.height;
_View2.frame = frameOld;
}
[UIView commitAnimations];
//显示信息
}
@end