UILabel 实现计算器界面

使用UILabel标签模拟显示计算机界面。代码实现如下:


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

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

        for (int j = 0; j < 4; ++j) {

            NSArray *arr = @[@[@"7",@"8",@"9",@"×"],@[@"4",@"5",@"6",@""],@[@"1",@"2",@"3",@""],@[@"     0",@"",@".",@"="]];

            

            UILabel *label = [[UILabel alloc]init];

            

            if (i == 3 && j == 0) {

                label.frame = CGRectMake(j * width, i * width + 20, width * 2 - 1.5, width - 1.5);

                label.textAlignment = NSTextAlignmentLeft;

            }else if(i == 3 && j == 1){

                

            }else{

                label.frame = CGRectMake(j * width, i * width + 20, width - 1.5, width - 1.5);

                label.textAlignment = NSTextAlignmentCenter;

            }

            if (j == 3) {

                label.backgroundColor = [UIColor orangeColor];

            }else{

                label.backgroundColor = [UIColor lightGrayColor];

            }

            

            label.text = arr[i][j];

            

            label.font = [UIFont systemFontOfSize:30];

            [self.view addSubview:label];

        }

    }

    

    

}


你可能感兴趣的:(ios,标签,UILabel,计算器)