#import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate{ //全局变量 UILabel*lablel; } -(void)dealloc{ self.window=nil; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor=[UIColor whiteColor]; [self.window makeKeyAndVisible]; //创建lablel lablel=[[UILabel alloc]initWithFrame:CGRectMake(20, 100, 280, 30)]; lablel.backgroundColor = [UIColor brownColor]; //设置文本 lablel.text = @"你好,helle world 你好,helle world 你好,helle world"; //设置文本颜色 lablel.textColor = [UIColor whiteColor]; //设置文本行数 lablel.numberOfLines = 0; //文本对齐方式 //lablel.textAlignment = NSTextAlignmentLeft; //lablel.textAlignment = NSTextAlignmentRight; lablel.textAlignment = NSTextAlignmentCenter; //获取系统的字体 NSLog(@"%@",[UIFont familyNames]); //设置字体和字号 lablel.font = [UIFont fontWithName:@"Tamil Sangam MN" size:15]; //加粗 lablel.font = [UIFont boldSystemFontOfSize:20]; //斜体 //lablel.font = [UIFont italicSystemFontOfSize:20]; //阴影颜色 //lablel.shadowColor = [UIColor redColor]; //阴影偏移 //lablel.shadowOffset = CGSizeMake(0, -10); //省略........ //lablel.lineBreakMode =NSLineBreakByTruncatingHead;//首部省略 //lablel.lineBreakMode =NSLineBreakByTruncatingMiddle;//中间省略 //lablel.lineBreakMode =NSLineBreakByTruncatingTail;//尾部省略 //高亮状态 lablel.highlighted = YES; //高亮字体颜色 lablel.highlightedTextColor = [UIColor greenColor]; //lablel自适应 //自动获取文本内容承载范围 //[lablel sizeToFit]; [self.window addSubview:lablel]; [lablel release]; //创建方式为类方法 //主要响应事件 //自定义UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btn.backgroundColor = [UIColor brownColor]; btn.frame = CGRectMake(20, 300, 200, 200); //按钮状态-设置文字与颜色 //普通状态 [btn setTitle:@"点我呀" forState:UIControlStateNormal]; [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; //高亮状态 [btn setTitle:@"别点我" forState:UIControlStateHighlighted]; [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; //禁用 //[btn setTitle:@"禁用" forState:UIControlStateDisabled]; //btn.enabled = YES; //设置按钮阴影颜色与偏移 //[btn setTitleShadowColor:[UIColor greenColor] forState:UIControlStateNormal]; //btn.titleShadowOffset = CGSizeMake(5, 5); //这样插入不推荐 //[btn setImage:[UIImage imageNamed:@"Button_foot1"] forState:UIControlStateNormal]; //把图片拉升至btn的size大小 [btn setBackgroundImage:[UIImage imageNamed:@"Button_foot1"] forState:UIControlStateNormal]; //创建uiimage对象 UIImage*image = [UIImage imageNamed:@"checked"]; //选中状态 [btn setBackgroundImage:image forState:UIControlStateSelected]; btn.selected = NO; btn.showsTouchWhenHighlighted = YES; // btn.imageView // btn.titleLabel lablel.text = @"0"; //添加事件 [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside ]; // [btn addTarget:self action:@selector(onClick: //) forControlEvents:UIControlEventTouchDown ]; [self.window addSubview:btn]; return YES; } -(void)onClick:(UIButton*)sender{ NSInteger n =[lablel.text intValue]+1; lablel.text = [NSString stringWithFormat:@"%d",n]; NSLog(@"%@",lablel.text); // if (sender.selected == NO) { // sender.selected = YES; // } // else // { // sender.selected = NO; // } // sender.enabled = NO; //可切换点击图标 sender.selected = ! sender.selected; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end
时间: 2024-11-12 19:21:58