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

下载方式:https://pan.quark.cn/s/b4d8292ba69a 在构建食品品牌的市场整合营销推广方案时,我们必须首先深入探究品牌的由来、顾客的感知以及市场环境。 此案例聚焦于一款名为“某饼干产品”的食品,该产品自1998年进入河南市场以来,经历了销售业绩的波动。 1999至2000年期间,其销售额取得了明显的上升,然而到了2001年则出现了下滑。 在先前的宣传活动中,品牌主要借助大型互动活动如ROAD SHOW来吸引顾客,但收效甚微,这揭示了宣传信息与顾客实际认同感之间的偏差。 通过市场环境剖析,我们了解到消费者对“3+2”苏打夹心饼干的印象是美味、时尚且充满活力,但同时亦存在口感腻、价位偏高、饼身坚硬等负面评价。 实际上,该产品可以塑造为兼具美味、深度与创新性的休闲食品,适宜在多种情境下分享。 这暗示着品牌需更精确地传递产品特性,同时消解消费者的顾虑。 在策略制定上,我们可考虑将新产品与原有的3+2苏打夹心进行协同推广。 这种策略的长处在于能够借助既有产品的声誉市场占有率,同时通过新产品的加入,刷新品牌形象,吸引更多元化的消费群体。 然而,这也可能引发一些难题,例如如何合理分配新旧产品间的资源,以及如何保障新产品的独特性吸引力不被既有产品所掩盖。 为了提升推广成效,品牌可以实施以下举措:1. **定位修正**:基于消费者反馈,重新确立产品定位,突出其美味、创新与共享的特性,减少消费者感知的缺陷。 2. **创新宣传**:宣传信息应与消费者的实际体验相契合,运用更具魅力的创意手段,例如叙事式营销,让消费者体会到产品带来的愉悦情感共鸣。 3. **渠道选择**:在目标消费者常去的场所开展活动,例如商业中心、影院或在线平台,以提高知名度参与度。 4. **媒体联...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值