十二星座图片缩放,夜间模式切换

本文介绍了一个iOS应用中用于展示星座信息的视图控制器实现。该控制器通过滑动条改变星座图片,并根据滑动位置更新相关星座名称及描述。此外,还提供了设置按钮来展开隐藏的设置面板,以及夜间模式开关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值