zoukankan      html  css  js  c++  java
  • iOS 九宫格的实现

    #import <UIKit/UIKit.h>

    @interface ViewController : UIViewController

    @property(strong,nonatomic) UILabel *lblNums;

    @end

    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

     int x=50,y=50,width=50,height=50;

        int a=1;

        for (int i=0; i<3; i++)

        {

            for (int j=0;j<3; j++)

            {

                self.lblNums=[[UILabel alloc] initWithFrame:CGRectMake(x+j*55, y+i*55, width, height)];

                

               self.lblNums.backgroundColor=[UIColor colorWithRed:(arc4random()%12/11.0) green:(arc4random()%23/22.0) blue:(arc4random()%34/33.0) alpha:1.0];

                

                NSString *newnum=[@(a) stringValue];

                    self.lblNums.text=newnum;

                    self.lblNums.textAlignment=1;

                    a++;

                    [self.view addSubview:self.lblNums];

            }

        }

        

    }

  • 相关阅读:
    2016第7周五
    优秀it博客和文章
    java惯用法转载
    2016第7周二
    人,终究是要找到自己喜欢的...才行
    2016第6周日
    2016第6周六
    2016第6周五
    2016第6周四
    2016第6周三
  • 原文地址:https://www.cnblogs.com/tmf-4838/p/5330550.html
Copyright © 2011-2022 走看看