码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 九宫格的实现

时间:2016-03-28 21:38:35      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

#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];

        }

    }

 

    

}

 

iOS 九宫格的实现

标签:

原文地址:http://www.cnblogs.com/tmf-4838/p/5330550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!