• 李洪强九宫格的实现


     这就是我要是实现的效果

     

     

     

    //

    //  LHQOilSeriesViewCtrl.m

    //  B01 - 首页

    //  油品系列控制器

     

    //  Created by vic fan on 16/6/30.

    //  Copyright © 2016 李洪强. All rights reserved.

    //

     

    #import "LHQOilSeriesViewCtrl.h"

    #define kSCREENW [UIScreen mainScreen].bounds.size.width

    #define kSCREENH [UIScreen mainScreen].bounds.size.height

    #define kMARGIN  10

    #define kIMAGEMARGIN 35

    #define kLABLEMARGIN 40

    @interface LHQOilSeriesViewCtrl ()

     

    @end

     

    @implementation LHQOilSeriesViewCtrl

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view.

        

        self.title = @"油品系列";

        self.view.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1];;

       //--------------------------------------------------

        //[UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1];

        

        

        

        

        [self addImage];

       // self.automaticallyAdjustsScrollViewInsets = NO;

        

        

        

    }

     

    - (void)addImage{

        

        //View的宽

        CGFloat viewW = (kSCREENW - 13*kMARGIN)/3.0;

        //图片的宽

        CGFloat imageviewW = (kSCREENW - 13*kIMAGEMARGIN)/3.0 - 10;

        //标题label的宽

        CGFloat labelW = (kSCREENW - 11*kLABLEMARGIN)/3.0 - 20;

        

        //VIew的高

        CGFloat viewH = (kSCREENH - 6*kMARGIN)/6.0;

        //图片的高

        CGFloat imageviewH = (kSCREENH - 6*kIMAGEMARGIN)/6.0 - 20;

        //label的高

        CGFloat labelH = (kSCREENH - 6*kLABLEMARGIN)/6.0 - 80;

        

        

        NSArray *imageArr = @[@"",@"",@"",@"",@""];

        NSArray *titleViewArr = @[@"机油",@"变速箱油"@"助力油",@"防冻液",@"玻璃水"];

     

        for(int i = 0; i < 5; i ++ ){

       

            //行数

            CGFloat rows  = i / 4;

            //列数

            CGFloat count = i % 4;

            //ViewX

            CGFloat viewX = kMARGIN + (viewW +kMARGIN)*count;

            //图片的X

            CGFloat imageviewX = kIMAGEMARGIN + (viewW +kMARGIN)*count+35;

            //labelX

            CGFloat labelX = kLABLEMARGIN + (viewW +kMARGIN)*count + 32;

            

            //ViewY

            CGFloat viewY = kMARGIN + (viewH +kMARGIN)*rows;

            //imageViewY

            CGFloat imageviewY = kIMAGEMARGIN + (viewH +kMARGIN)*rows - 10;

            //labelY

            CGFloat labelY = kLABLEMARGIN + (viewH +kMARGIN)*rows + 60;

            //创建View

            UIView *mainView = [[UIView alloc]initWithFrame:CGRectMake(viewX, viewY+64, viewW, viewH)];

            mainView.backgroundColor = [UIColor whiteColor];

            [self.view addSubview:mainView];

            

            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(imageviewX, imageviewY + 64, imageviewW, imageviewH)];

            imageView.image = [UIImage imageNamed:@""];

            imageView.backgroundColor = [UIColor redColor];

            

          //  NSArray *titleArr = @[@"机油",@"变速油箱",@"助力油",@"防冻液",@"玻璃水"];

            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(labelX, labelY + 64, labelW, labelH)];

            label.font = [UIFont systemFontOfSize:10];

           // label.backgroundColor = [UIColor orangeColor];

            //设置lable的文字居中

            label.textAlignment = UITextAlignmentCenter;

            

            [self.view addSubview:imageView];

            [self.view addSubview:label];

            

            if(i == 0){

                label.text = @"机油";

                imageView.image = [UIImage imageNamed:@"Snip20160701_80"];

            }else if (i == 1){

                label.text = @"变速油箱";

                imageView.image = [UIImage imageNamed:@"Snip20160701_81"];

            }else if (i == 2){

                

                label.text = @"助力油";

                imageView.image = [UIImage imageNamed:@"Snip20160701_82"];

            }else if (i == 3){

                

                label.text = @"防冻液";

                imageView.image = [UIImage imageNamed:@"Snip20160701_83"];

            }else if (i == 4){

                

                label.text = @"玻璃水";

                imageView.image = [UIImage imageNamed:@"Snip20160701_84"];

            }

           // label.text = titleViewArr[i];

            

            

            

        }

        

    }

     

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    /*

    #pragma mark - Navigation

     

    // In a storyboard-based application, you will often want to do a little preparation before navigation

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

        // Get the new view controller using [segue destinationViewController].

        // Pass the selected object to the new view controller.

    }

    */

     

    @end

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • 相关阅读:
    1012 最大公约数和最小公倍数问题 2001年NOIP全国联赛普及组
    数论笔记
    Codevs 1200 同余方程 2012年NOIP全国联赛提高组
    Codevs 1213 解的个数(exgcd)
    Qbxt 模拟赛&&day-8
    NOIP 模拟赛 那些年,我们学过的文化课 --致已退役的fqk神犇.
    OI路上 day -9
    P3178 [HAOI2015]树上操作
    P3979 遥远的国度
    P4092 [HEOI2016/TJOI2016]树
  • 原文地址:https://www.cnblogs.com/LiLihongqiang/p/5633984.html
Copyright © 2020-2023  润新知