iOS纯代码制作欢迎界面——UIScrollView, UIPageControl, UIImageView,UIButton, NSTimer

  欢迎界面,还是比较简单的,一个UIScrollView控件,一个UIPageControl,几个UIImageView即可摆平。在这里光玩这些,就显得诚意不足了。特意拓展一下,再加几个UIButton,可以让这个欢迎界面变成可点击的,可滑动的模块添加在页面中,然后再加一个NSTimer,让它自己隔2秒自己循环滑动着,立马让它变成可以放在主页用于展示主打商品的模块。

  下面直接展示可直接运行的Demo,代码都挺简单,这次就不添加注解了。

#import "ViewController.h"

 

@interface ViewController ()<UIScrollViewDelegate>

@property(nonatomic,strong) UIScrollView *scrollerView;

 

@property(nonatomic,strong) NSArray *images;

@property(nonatomic,strong) NSMutableArray *imageButtons;

 

@property(nonatomic,strong) UIPageControl *pageControl;

@end

 

@implementation ViewController

 

-(NSArray *)images{

    if (!_images) {

        _images = @[@"1.png",@"2.png",@"3.png",@"4.png",@"5.png",@"6.png"];

    }

    return _images;

}

 

-(NSMutableArray *)imageButtons{

    if (!_imageButtons) {

        _imageButtons = [NSMutableArray array];

    }

    return _imageButtons;

}

 

- (void)viewDidLoad {

    [super viewDidLoad];

    

    [self initScrollerView];

}

 

-(void)initScrollerView{

    UIScrollView *scrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

    self.scrollerView = scrollerView;

    scrollerView.contentSize = CGSizeMake(self.view.bounds.size.width * self.images.count, self.view.bounds.size.height);

    scrollerView.pagingEnabled = YES;

    scrollerView.bounces = NO;

    scrollerView.delegate = self;

    [self.view addSubview:scrollerView];

    

    for (int i = 0; i<self.images.count; i++) {

        UIImage *image = [UIImage imageNamed:self.images[i]];

        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

        imageView.frame = CGRectMake(self.view.bounds.size.width * i, 0, self.view.bounds.size.width, self.view.bounds.size.height);

        imageView.contentMode = UIViewContentModeScaleToFill;

        [scrollerView addSubview:imageView];

        

        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

        button.frame = CGRectMake(self.view.bounds.size.width * i, 0, self.view.bounds.size.width, self.view.bounds.size.height);

        button.backgroundColor = [UIColor clearColor];

        [button addTarget:self action:@selector(clickScrollerViewButton:) forControlEvents:UIControlEventTouchUpInside];

        [scrollerView addSubview:button];

        [self.imageButtons addObject:button];

    }

    

    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, scrollerView.bounds.size.height - 20, scrollerView.bounds.size.width, 10)];

    self.pageControl = pageControl;

    pageControl.numberOfPages = self.images.count;

    pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];

    pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];

    pageControl.userInteractionEnabled = NO;

    [pageControl addTarget:self action:@selector(clickScrollerViewButton:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:pageControl];

    

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(changeImageByTimer) userInfo:nil repeats:YES];

    [timer fireDate];

}

 

-(void)clickScrollerViewButton:(UIButton*)button{

    NSInteger num = [self.imageButtons indexOfObject:button];

    NSLog(@"%ld",(long)num);

}

 

-(void)changeImageByTimer{

    self.pageControl.currentPage = (self.pageControl.currentPage+1)%self.images.count;

    self.scrollerView.contentOffset = CGPointMake(self.pageControl.currentPage * self.view.bounds.size.width, 0);

}

 

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    CGPoint point = scrollView.contentOffset;

    NSInteger index = point.x / scrollView.frame.size.width;

    self.pageControl.currentPage = index;

}

 

@end

 

转载于:https://www.cnblogs.com/yyt-hehe-yyt/p/4732066.html

内容概要:本文详细介绍了一个基于CNN-GRU与AdaBoost集成的深度学习模型在时间序列预测中的完整项目实现。该模型通过卷积神经网络(CNN)提取局部时空特征,利用门控循环单元(GRU)捕捉长期时序依赖,并结合AdaBoost自适应提升算法增强模型泛化能力与鲁棒性,有效应对非线性、噪声干扰和复杂动态变化的挑战。项目涵盖从数据生成、预处理、模型构建、训练优化到结果可视化和GUI交互界面开发的全流程,提供了完整的代码示例与模块化系统架构设计,支持金融、能源、交通、医疗等多个领域的高精度预测应用。; 适合人群:具备一定Python编程基础和机器学习知识,熟悉深度学习框架(如TensorFlow/Keras)的数据科学家、算法工程师及高校研究人员,尤其适合从事时间序列分析、智能预测系统开发的相关从业者。; 使用场景及目标:①实现高精度时间序列预测,如股票价格、电力负荷、交通流量等;②构建具备强鲁棒性和抗噪能力的工业级预测系统;③开发集成深度学习与集成学习的复合模型以提升预测稳定性;④通过GUI界面实现模型的便捷部署与交互式分析。; 阅读建议:建议读者结合文档中的代码逐步实践,重点关注数据预处理、模型集成机制与可视化模块的设计逻辑,同时可在不同数据集上进行迁移实验,深入理解CNN-GRU与AdaBoost协同工作的原理与优势。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值