- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
for (int i=1; i<10; i++) {
BOOL a = YES;
for (int j=i; j<10; j++) {
// UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 12, 30, 10)];
// NSString *str = [NSString stringWithFormat:@"%d*%d=%d",i,j,i*j];
// label1.text = [NSString stringWithString:str];
// label1.textAlignment = NSTextAlignmentCenter;
// label1.font =[UIFont systemFontOfSize:9];
//
// UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake((i-1)*35, 50+(j-1)*30, 35, 30)];
//
//
// if (a == YES) {
// view1.backgroundColor = [UIColor greenColor];
// a=NO;
// }else{
// view1.backgroundColor = [UIColor redColor];
// a=YES;
// }
// [self.window addSubview:view1];
// [view1 addSubview:label1];
//
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake((i-1)*35, 50+(j-1)*30, 35, 30)];
NSString *str = [NSString stringWithFormat:@"%d*%d=%d",i,j,i*j];
label1.text = [NSString stringWithString:str];
label1.textAlignment = NSTextAlignmentCenter;
label1.font =[UIFont systemFontOfSize:10];
// UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake((i-1)*35, 50+(j-1)*30, 35, 30)];
if (a == YES) {
label1.backgroundColor = [UIColor greenColor];
a=NO;
}else{
label1.backgroundColor = [UIColor yellowColor];
a=YES;
}
[self.window addSubview:label1];
// [view1 addSubview:label1];
}
}
return YES;
}UI_View01 输出九九乘法表
最新推荐文章于 2023-03-14 15:59:05 发布
本文介绍如何使用Objective-C在iOS应用中创建一个动态的乘法表视图。通过循环迭代的方式设置UILabel来显示乘法表的内容,并利用条件判断为每个标签赋予不同的背景颜色以增强视觉效果。

181

被折叠的 条评论
为什么被折叠?



