【代码笔记】底下滚动,上面标题栏也会跟着变动,笔记标题栏

【代码笔记】电影上的花絮,自动滚动,代码笔记花絮滚动

一,效果图。

亚洲城ca88手机版官网 1

二,工程图。

亚洲城ca88手机版官网 2

三,代码。

RootViewController.h

亚洲城ca88手机版官网 3

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
<UIScrollViewDelegate>
{
    UIScrollView *scoreView;
}
@end

亚洲城ca88手机版官网 4

亚洲城ca88手机版官网, 

RootViewController.m

亚洲城ca88手机版官网 5

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self initBackgroundView];
}
#pragma -mark -functions
-(void)initBackgroundView
{
    self.view.backgroundColor=[UIColor greenColor];

    scoreView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 100, 320, 140)];
    scoreView.backgroundColor=[UIColor greenColor];
    scoreView.contentSize=CGSizeMake(320*3, 140);
    scoreView.showsVerticalScrollIndicator=NO;
    scoreView.showsHorizontalScrollIndicator=NO;
    scoreView.scrollEnabled=NO;
    scoreView.delegate=self;
    [self.view addSubview:scoreView];


    for (int i=0; i<4; i++) {
        UIImageView* imageView=[[UIImageView alloc]initWithFrame:CGRectMake(i*320, 0, 320, 140)];
         imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]];
        if (i==3) {
            imageView.image=[UIImage imageNamed:@"0.jpg"];
        }
        [scoreView addSubview:imageView];
    }

    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timer:) userInfo:nil repeats:YES];


    UIPageControl* pc = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 220, 320, 20)];
    pc.numberOfPages = 3;
    pc.tag=100;
    [pc addTarget:self action:@selector(pc:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:pc];


}
-(void)timer:(NSTimer *)timer{

    if (scoreView.contentOffset.x==320*3) {
        scoreView.contentOffset=CGPointMake(0, 0);
    }
    [scoreView setContentOffset:CGPointMake(scoreView.contentOffset.x+320,0) animated:YES];
}
- (void)pc:(UIPageControl*)pc{
    scoreView.contentOffset=CGPointMake(pc.currentPage*320, 0);
}
#pragma -mark -UIScrollerViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    UIPageControl* pc = (UIPageControl*)[self.view viewWithTag:100];
    pc.currentPage = scrollView.contentOffset.x / 320;
    if (scoreView.contentOffset.x==320*3) {
        pc.currentPage=0;
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

亚洲城ca88手机版官网 6

 

一,效果图。 二,工程图。 三,代码。 RootViewController.h #import
UIKit/[email protected]

【代码笔记】底下滚动,上面标题栏也会跟着变动,笔记标题栏

一,效果图。

亚洲城ca88手机版官网 7

二,工程图。

亚洲城ca88手机版官网 8

三,代码。

RootViewController.h

亚洲城ca88手机版官网 9

#import <UIKit/UIKit.h>
#import "SVSegmentedControl.h"

@interface RootViewController : UIViewController
<UIScrollViewDelegate>
{
    UIScrollView *scrollView1;
    UIScrollView *scrollView2;
    UIPageControl *pag;
    NSMutableArray *dataArray;
    SVSegmentedControl *options;
}

@end

亚洲城ca88手机版官网 10

 

RootViewController.m

亚洲城ca88手机版官网 11

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    //初始化背景图
    [self initBackGroundView];
}
#pragma -mark -functions
-(void)initBackGroundView
{
    //隐藏导航条
    self.navigationController.navigationBarHidden=YES;

    //底部的滚动条
    scrollView1=[[UIScrollView alloc]init];
    scrollView1.frame=CGRectMake(0, 40, 320, 400);
    scrollView1.backgroundColor=[UIColor grayColor];
    scrollView1.delegate=self;
    scrollView1.pagingEnabled=YES;
    scrollView1.contentSize=CGSizeMake(320*2, 376);
    [self.view addSubview:scrollView1];

    //第一页的内容
    UIView *v1=[[UIView alloc]init];
    [v1 setFrame:CGRectMake(0, 0, 320, 376)];
    v1.backgroundColor=[UIColor redColor];
    [scrollView1 addSubview:v1];

    //第二页的内容
    UIView *v2=[[UIView alloc]init];
    v2.frame=CGRectMake(320, 0, 320, 376);
    v2.backgroundColor=[UIColor blueColor];
    [scrollView1 addSubview:v2];

    //下面指示页的圆点
    pag=[[UIPageControl alloc]initWithFrame:CGRectMake(160, 400, 0, 0)];
    pag.numberOfPages=2;
    pag.currentPage=0;
    [self.view addSubview:pag];

    //上面的滑动图标
    options = [[SVSegmentedControl alloc] initWithSectionTitles:[NSArray arrayWithObjects:@"购车应用",@"车主应用", nil]];
    [options addTarget:self action:@selector(actiBtClick:) forControlEvents:UIControlEventValueChanged];
    [options setBackgroundImage:[UIImage imageNamed:@"switchBg.png"]];
    options.center=CGPointMake(160, 50);
    options.crossFadeLabelsOnDrag=YES;
    options.selectedIndex=0;
    options.textColor=[UIColor blackColor];
    options.LKWidth=120;
    options.textShadowOffset=CGSizeMake(0, 0);
    options.textShadowColor=[UIColor clearColor];
    options.height=30;
    options.thumb.backgroundImage=[UIImage imageNamed:@"按钮-2.png"];
    options.thumb.highlightedBackgroundImage=[UIImage imageNamed:@"按钮-2.png"];
    options.thumb.textShadowColor=[UIColor clearColor];
    options.thumb.textShadowOffset=CGSizeMake(0, 0);
    [self.view addSubview:options];


}
#pragma -mark -doClickActions
- (void)actiBtClick:(SVSegmentedControl *)sender
{
    if(sender.selectedIndex==0)
    {
        [scrollView1 setContentOffset:CGPointMake(0, scrollView1.contentOffset.y) animated:YES];
        pag.currentPage=0;
    }
    else if(sender.selectedIndex==1)
    {
        [scrollView1 setContentOffset:CGPointMake(320, scrollView1.contentOffset.y) animated:YES];
        pag.currentPage=1;
    }
}
#pragma -mark -scrollViewDelegate
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if(scrollView1.contentOffset.x==0)
    {
        pag.currentPage=0;
        [options moveThumbToIndex:0 animate:YES];
    }
    else if(scrollView1.contentOffset.x==320)
    {
        pag.currentPage=1;
        [options moveThumbToIndex:1 animate:YES];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

亚洲城ca88手机版官网 12

 

一,效果图。 二,工程图。 三,代码。 RootViewController.h #import
UIKit/UIKit….

【代码笔记】iOS-TableViewOfTwoSecton,代码笔记

一,效果图。

亚洲城ca88手机版官网 13

二,工程图。

亚洲城ca88手机版官网 14

三,代码。

RootViewController.h

亚洲城ca88手机版官网 15

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
<UITableViewDataSource,UITableViewDelegate>
{
    NSArray * dataArray;
    NSArray * aboutArray;
}

@end

亚洲城ca88手机版官网 16

 

RootViewController.m

亚洲城ca88手机版官网 17

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.title=@"tableViewOfTwoSection";
    //初始化背景图
    [self initBackGroundView];
    //初始化数据
    [self initData];
}
#pragma -mark -funcitons
-(void)initBackGroundView
{
    UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 376) style:UITableViewStyleGrouped];
    tableview.delegate = self;
    tableview.dataSource = self;
    [self.view addSubview:tableview];

}
-(void)initData
{
    dataArray = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"脑筋急转弯", @"title", nil],[NSDictionary dictionaryWithObjectsAndKeys:@"儿童饮食", @"title",  nil], [NSDictionary dictionaryWithObjectsAndKeys:@"儿童健康", @"title",  nil],[NSDictionary dictionaryWithObjectsAndKeys:@"宝宝资讯", @"title",  nil],nil];

    aboutArray = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"关于", @"title", @"aboutViewController", @"class", nil], nil];
}
#pragma -mark -UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section==0)
    {
        return dataArray.count;
    }
    else if(section==1)
    {

        return aboutArray.count;
    }
    return 0;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
    if(cell==nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ID"];

    }
    if(indexPath.section==0){
        cell.textLabel.text =[[dataArray objectAtIndex:indexPath.row]objectForKey:@"title"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else if(indexPath.section==1)
    {
        cell.textLabel.text = [[aboutArray objectAtIndex:indexPath.row]objectForKey:@"title"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section==0)
    {
        if(indexPath.row==0)
        {
            NSLog(@"脑筋急转弯");
        }else if (indexPath.row==1){
            NSLog(@"儿童饮食");
        }else if (indexPath.row==2){
            NSLog(@"儿童健康");
        }else if (indexPath.row==3){
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://baby.163.com"]];
        }

    }else if (indexPath.section==1) {
        if(indexPath.row==0)
        {
            NSLog(@"关于");
        }
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

一,效果图。 二,工程图。 三,代码。 RootViewController.h #import
UIKit/UIKit.h @interface RootViewContro…

Copyright @ 2015-2019 ca88 版权所有
网站地图xml地图