UIday01_zy: 用iPhone6模拟器设计一个6行5列的label,并把百家姓放进去

来源:互联网 发布:淘宝怎么购买淘金币 编辑:程序博客网 时间:2024/06/05 23:05


self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];    self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];    NSArray * arr = @[@"赵",@"钱",@"孙",@"李",@"周",@"吴",@"郑",@"王",@"冯",@"陈",@"楮",@"卫",@"蒋",@"沈",@"韩",@"杨",@"朱",@"秦",@"尤",@"许",@"何",@"吕",@"施",@"张",@"孔",@"曹",@"严",@"华",@"金",@"魏"];    //375 * 667  (宽 375.0/5 高 667.0/6)    CGFloat w = 375.0/5;    CGFloat h = 667.0/6;    for (int i =0; i<6; i++) {        for (int j = 0; j<5; j++) {            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(w * j, h * i, w, h)];            lab.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:arc4random()%256/255.0];            lab.text = arr[i*5+j];            lab.textAlignment = NSTextAlignmentCenter;            [self.window addSubview:lab];        }    } 


0 0
原创粉丝点击