uiscrollview和uipagecontrol组合

经过网上一个demo的分析和运用加以改善的万能代码,只需将下面的.h和.m文件的代码直接复制到你的工程的这个控制器的。h和。m文件下即可,不过还是要看一下代码中property声明的东西,这里面- (void)createPages方法里的图片名字换成你的图片名字就好了,如有疑问联系我哦

不多说,直接上码:

.h文件

#import <UIKit/UIKit.h>

 

@interface PageViewController : UIViewController<UIScrollViewDelegate>

 

@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;

@property (strong, nonatomic) IBOutlet UIPageControl *pageControl;

 

- (void)createPages;

- (IBAction)return:(id)sender;

 

@end

 

.m文件

 

#import “PageViewController.h”

 

@interface PageViewController ()

 

- (void)loadScrollViewWithPage:(UIView *)page;

- (void)scrollViewDidScroll:(UIScrollView *)sender;

 

@end

 

@implementation PageViewController

@synthesize scrollView;

@synthesize pageControl;

 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {

// Custom initialization

}

return self;

}

 

- (void)viewDidLoad

{

[super viewDidLoad];

[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"mysteel_login_bg"]]];

int pageCount = 5;

CGRect scrollViewRect = [self.view bounds];

//create scrollview

scrollView.pagingEnabled = YES;

scrollView.contentSize = CGSizeMake(scrollViewRect.size.width * (pageCount+1),0);

scrollView.showsHorizontalScrollIndicator = NO;

scrollView.showsVerticalScrollIndicator = NO;

scrollView.delegate = self;

pageControl.numberOfPages = pageCount;

[pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];

//create pages

[self createPages];

// Do any additional setup after loading the view.

[self.view addSubview:pageControl];

}

 

- (void)viewDidUnload

{

[super viewDidUnload];

[self setScrollView:nil];

[self setPageControl:nil];

// Release any retained subviews of the main view.

}

 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

 

#pragma mark 图片切换

- (void)loadScrollViewWithPage:(UIView *)page

{

int pageCount = [[scrollView subviews] count];        //这一句施舍呢意思?

CGRect bounds = scrollView.bounds;

bounds.origin.x = bounds.size.width * pageCount;

bounds.origin.y = 0;

page.frame = bounds;

[scrollView addSubview:page];

}

 

- (void)scrollViewDidScroll:(UIScrollView *)sender

{

CGFloat pageWidth = sender.frame.size.width;

int page = floor((sender.contentOffset.x – pageWidth / 2) / pageWidth) + 1;

pageControl.currentPage = page;

}

 

- (void)createPages

{

CGRect pageRect = scrollView.frame;

//create pages

UIView *page1 = [[UIView alloc] initWithFrame:pageRect];

page1.backgroundColor = [UIColor blackColor];

[page1 setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"1.png"]]];

UIView *page2 = [[UIView alloc] initWithFrame:pageRect];

page2.backgroundColor = [UIColor blackColor];

[page2 setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"2.png"]]];

UIView *page3 = [[UIView alloc] initWithFrame:pageRect];

page3.backgroundColor = [UIColor blackColor];

[page3 setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"3.png"]]];

UIView *page4 = [[UIView alloc] initWithFrame:pageRect];

page4.backgroundColor = [UIColor blackColor];

[page4 setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"4.png"]]];

UIView *page5 = [[UIView alloc] initWithFrame:pageRect];

page5.backgroundColor = [UIColor blackColor];

[page5 setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"5.png"]]];

self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * 5, self.scrollView.frame.size.height);

[self loadScrollViewWithPage:page1];

[self loadScrollViewWithPage:page2];

[self loadScrollViewWithPage:page3];

[self loadScrollViewWithPage:page4];

[self loadScrollViewWithPage:page5];

}

 

- (void)changePage:(id)sender

{

int page = pageControl.currentPage;

// update the scroll view to the appropriate page

CGRect frame = scrollView.frame;

frame.origin.x = frame.size.width * page;

frame.origin.y = 0;

[scrollView scrollRectToVisible:frame animated:YES];

}

- (IBAction)return:(id)sender {

[self dismissModalViewControllerAnimated:YES];

}

@end

【顶级EI完美复现】电力系统碳排放流的计算方法【IEEE 14节点】(Matlab代码实现)内容概要:本文介绍了名为《【顶级EI完美复现】电力系统碳排放流的计算方法【IEEE 14节点】(Matlab代码实现)》的技术文档,核心内容是基于IEEE 14节点电力系统模型,利用Matlab实现碳排放流的精确计算方法。该方法通过建立电力系统中各节点的功率流动与碳排放之间的映射关系,实现对电能传输过程中碳足迹的追踪与量化分析,属于电力系统低碳调度与碳流管理领域的关键技术。文中强调“顶级EI完美复现”,表明其算法仿真结果具有较高的学术严谨性可重复性,适用于科研验证与教学演示。; 适合人群:电力系统、能源与动力工程、电气工程及其自动化等相关专业的研究生、科研人员以及从事电力系统低碳化、碳排放核算工作的技术人员。; 使用场景及目标:①用于电力系统碳排放流理论的学习与仿真验证;②支撑含新能源接入的电力系统低碳调度、碳交易、绿色电力溯源等课题的研究;③为撰写高水平学术论文(如EI/SCI期刊)提供可靠的代码基础技术参考。; 阅读建议:读者应具备电力系统分析、Matlab编程的基础知识,建议结合电力系统潮流计算、节点导纳矩阵等前置知识进行学习,并通过调整系统参数运行方式,深入理解碳排放流的分布规律与影响因素。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值