UI -UIView和UILabel控件
2015-08-22 15:33
411 查看
// 在ARC下可以重写dealloc方法 但是不能使用[super dealloc] - (void)dealloc { [_window release]; [super dealloc]; } /* - (void)test { // 取出tag值为100的view,修改其背景颜色为红色 UIView *view = [self.window viewWithTag:100]; view.backgroundColor = [UIColor redColor]; } */ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { /* Window *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window = window; [window release]; */ // 1.创建一个与屏幕等大的window self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease]; // Override point for customization after application launch. // 2.设置window的背景颜色 self.window.backgroundColor = [UIColor blackColor]; // 3.使用当前的window成为主窗口并且可见 [self.window makeKeyAndVisible]; /* // 1.按照课件上的代码创建一个UIView对象 // 1>创建UIView // 1.初始化方法 // 2.便利构造器 UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)]; // 2>设置UIView相关属性 blueView.backgroundColor = [UIColor blueColor]; // frame center是UIView的属性 frame和center在修改的时候 影响的是自身在父视图上的位置 是相对于父视图而言的 // 每一个View都有自身的一套坐标系 // blueView.center = CGPointMake(120, 120); // blueView.frame = CGRectMake(30, 30, 80, 60); // 打印blueView对应的bounds属性 // NSLog(@"%f,%f,%f,%f",blueView.bounds.origin.x,blueView.bounds.origin.y,blueView.bounds.size.width,blueView.bounds.size.height); NSLog(@"%@",NSStringFromCGRect(blueView.bounds)); // blueView.bounds = CGRectMake(10, 0, 100, 100); // 1)blueView 在父视图上得位置有没有发生变化 ==>没有发生变化 // 2)修改了一个视图的bounds之后 会对什么产生影响 ==> // 1.如果只是修改了bounds的origin 会对该视图上的子视图产生影响 // 2.如果修改了bounds的size 会对franme产生影响 但是center不会改变 // 3>将其添加到父视图 [self.window addSubview:blueView]; NSLog(@"%@",self.window.subviews); */ /* UIView *yellowView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 50, 50)]; yellowView.backgroundColor = [UIColor yellowColor]; [self.window addSubview:yellowView]; [yellowView release]; UIView *greenView = [[UIView alloc]initWithFrame:CGRectMake(150, 150, 50, 50)]; greenView.backgroundColor = [UIColor greenColor]; [self.window addSubview:greenView]; [greenView release]; CGRect test = CGRectMake(100, 150, 50, 50); UIView *redView = [[UIView alloc]initWithFrame:test]; redView.backgroundColor = [UIColor redColor]; [self.window addSubview:redView]; [redView release]; */ /* // 2.创建一个UIView对象 对象的Frame为(100,100,200,250) 颜色为黄色,添加到window上 // 1>创建UIView // 1.初始化方法 // 2.便利构造器 UIView *yellowView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)]; // 2>设置UIView相关属性 yellowView.backgroundColor = [UIColor yellowColor]; // 练习: 1.修改yellowView的bounds为CGRectMake(10,0,200,250) // 2.把blueView添加到yellowView上面 // 3.看看会产生什么样的影响 思考一下为什么会产生这样的影响 yellowView.bounds = CGRectMake(30, 0, 200, 200); // 3>将其添加到父视图 [self.window addSubview:yellowView]; yellowView.alpha = 1; UIView *greenView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; greenView.backgroundColor = [UIColor greenColor]; // greenView.bounds = CGRectMake(10, 0, 100, 100); [yellowView addSubview:greenView]; greenView.alpha = 0.5; greenView.tag = 100; [self.window insertSubview:yellowView atIndex:3]; NSLog(@"%@",self.window.subviews); [self test]; // 4>释放 [blueView release]; [yellowView release]; [greenView release]; UIView *containView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 250, 180)]; containView.backgroundColor = [UIColor lightGrayColor]; [self.window addSubview:containView]; containView.center = CGPointMake(190, 280); UIView *redView1 = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 60, 30)]; redView1.backgroundColor = [UIColor redColor]; [containView addSubview:redView1]; UIView *redView2 = [[UIView alloc]initWithFrame:CGRectMake(30, 70, 60, 30)]; redView2.backgroundColor = [UIColor redColor]; [containView addSubview:redView2]; UIView *blueView1 =[[UIView alloc]initWithFrame:CGRectMake(110, 30, 110, 30)]; blueView1.backgroundColor = [UIColor blueColor]; [containView addSubview:blueView1]; UIView *blueView2 =[[UIView alloc]initWithFrame:CGRectMake(110, 70, 110, 30)]; blueView2.backgroundColor = [UIColor blueColor]; [containView addSubview:blueView2]; UIView *greenView1 =[[UIView alloc]initWithFrame:CGRectMake(30, 120, 50, 30)]; greenView1.backgroundColor = [UIColor greenColor]; [containView addSubview:greenView1]; UIView *greenView2 =[[UIView alloc]initWithFrame:CGRectMake(100, 120, 50, 30)]; greenView2.backgroundColor = [UIColor greenColor]; [containView addSubview:greenView2]; UIView *greenView3 =[[UIView alloc]initWithFrame:CGRectMake(170, 120, 50, 30)]; greenView3.backgroundColor = [UIColor greenColor]; [containView addSubview:greenView3]; [containView release]; [greenView3 release]; [greenView2 release]; [greenView1 release]; [blueView2 release]; [blueView1 release]; [redView2 release]; [redView1 release]; */ UIView *containView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 250, 180)]; containView.backgroundColor = [UIColor lightGrayColor]; [self.window addSubview:containView]; containView.center = CGPointMake(190, 280); [containView release]; /** * UILabel:显示文本的控件 任何控件的创建都是分为4步 */ // 1.创建对象 UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 150)]; // 2.设置相关属性 label.backgroundColor = [UIColor whiteColor]; label.text = @"nozuonodie"; label.textColor = [UIColor purpleColor]; label.textAlignment = NSTextAlignmentCenter; label.lineBreakMode = NSLineBreakByCharWrapping; label.numberOfLines = 3; label.shadowColor = [UIColor blackColor]; label.shadowOffset = CGSizeMake(2, 1); // 3.添加到父视图上 [containView addSubview:label]; // 4.释放 [label release]; // 字体 字体集 // 黑体 黑体加粗 黑体倾斜 // 1.获取所有的字体集 NSArray *arr = [UIFont familyNames]; NSLog(@"%@",arr); // 2.获得字体集里面对应的字体 NSArray *fontArr = [UIFont fontNamesForFamilyName:@"Lao Sangam MN"]; NSLog(@"%@",fontArr); label.font = [UIFont fontWithName:@"LaoSangamMN" size:30]; label.font = [UIFont systemFontOfSize:25]; return YES; }
相关文章推荐
- GUI - Web前端开发框架
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 评价ui设计作品好坏的八个标准(界面/交互设计研究)
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 为Yahoo! UI Extensions Grid增加内置的可编辑器
- Cocos2d-x UI开发之文本类使用实例
- 在IE 浏览器中使用 jquery的fadeIn() 效果 英文字符字体加粗
- UI Events 用户界面事件
- 基于jQuery UI CSS Framework开发Widget的经验
- jquery ui 1.7 ui.tabs 动态添加与关闭(按钮关闭+双击关闭)
- jQuery UI的Dialog无法提交问题的解决方法
- 关于jQuery UI 使用心得及技巧
- jQuery ui 1.7更新小结
- 从零开始学习jQuery (十) jQueryUI常用功能实战
- jquery ui对话框实例代码