轮播图

作者: 呵邢 | 来源:发表于2018-10-29 11:46 被阅读0次
    #import "ViewController.h"
    
    #import "MainViewController.h"
    #import "UIView+SDAutoLayout.h"
    
    
    @interface ViewController ()<UIScrollViewDelegate>
    
    @property(nonatomic,strong)UIScrollView *scrollView;
    
    @end
    
    @implementation ViewController
    -(void)viewWillAppear:(BOOL)animated
    {
        self.navigationController.navigationBar.hidden = YES;
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
      
        [self scrollViewItem];
    
        
        
        
        
    }
    -(void)scrollViewItem
    {
        self.scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
        
        self.scrollView.delegate = self;
        
        self.scrollView.contentSize = CGSizeMake(3 * self.view.frame.size.width, self.view.frame.size.height);
        
        self.scrollView.bounces = NO;
        
        self.scrollView.pagingEnabled = YES;
        
        self.scrollView.showsVerticalScrollIndicator = NO;
        
        for (int i = 0; i < 3; i++)
        {
            UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(i*self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
            NSArray *arr = @[@"1",@"2",@"3"];
            
            imgV.image = [UIImage imageNamed:arr[i]];
            
            if (i == 2)
            {
                UIButton *btn = [[UIButton alloc]init];
                [imgV addSubview:btn];
                btn.sd_layout.topSpaceToView(self, 20).leftSpaceToView(self, 300).widthIs(90).heightIs(30);
                [btn setTitle:@"立即体验" forState:(UIControlStateNormal)];
                [btn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    
                [btn addTarget:self action:@selector(btnClick) forControlEvents:(UIControlEventTouchUpInside)];
                
                imgV.userInteractionEnabled = YES;
            }
            
            [ self.scrollView addSubview:imgV];
        }
        [self.view addSubview: self.scrollView];
        
    }
    
    -(void)btnClick
    {
        MainViewController *mainView = [[MainViewController alloc]init];
        [self.navigationController pushViewController:mainView animated:YES];
    }
    
    
    @end
    
    

    相关文章

      网友评论

          本文标题:轮播图

          本文链接:https://www.haomeiwen.com/subject/oxcizftx.html