ios学习第五天(三)View常用操作
来源:互联网 发布:为什么谭咏麟你知我知 编辑:程序博客网 时间:2024/06/13 08:42
上一篇我们给一个view中添加了许多子view,现在对view进行操作,还是先看结果
看代码和注释:
//// ViewController.m// HelloIOS//// Created by Moluth on 17/4/10.// Copyright (c) 2017年 Moluth. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[[UIColor alloc] initWithRed:0.3f green:0.35f blue:0.85f alpha:1.0f]; UIView *view1=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];//创建view ,view是矩形,0,0表示左上角坐标,后面的100,100代表宽高 view1.backgroundColor=[[UIColor alloc] initWithRed:0.88f green:0.66f blue:0.11f alpha:0.8f];//给新创建的view设置背景颜色,便于观察 [self.view addSubview:view1];//向ViewController中的view中添加子View //下面代码都是对上面的复制和修改,仅仅是坐标和颜色不同 UIView *view2=[[UIView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)]; view2.backgroundColor=[[UIColor alloc] initWithRed:1.0f green:0.0f blue:0.6f alpha:0.8f]; [self.view addSubview:view2]; UIView *view3=[[UIView alloc] initWithFrame:CGRectMake(60, 60, 100, 100)]; view3.backgroundColor=[[UIColor alloc] initWithRed:1.0f green:1.0f blue:0.6f alpha:0.8f]; [self.view addSubview:view3]; UIView *view4=[[UIView alloc] initWithFrame:CGRectMake(90, 90, 100, 100)]; view4.backgroundColor=[[UIColor alloc] initWithRed:0.0f green:1.0f blue:0.0f alpha:0.8f]; [self.view addSubview:view4]; /////////////////////////////////////下面是新添加的代码/////////////////////////////////////////////////// view1.alpha=0.9;//设置view1的透明度 view1.center=self.view.center;//让view1的中心点与父view中心点对齐 view1.tag=123;//设置标签 if([self.view viewWithTag:123]==view1){ NSLog(@"same"); }//输出 same [self.view bringSubviewToFront:view2];//把view2放到前面显示 [self.view sendSubviewToBack:view4];//把view4放到后面面显示 /* [view1 removeFromSuperview];//把view1从父view中移除 //那么 if([self.view viewWithTag:123]==view1){ NSLog(@"same"); }//可以输出 same吗????? */ //self.view // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- ios学习第五天(三)View常用操作
- ios学习第五天(二)给页面中的View添加子View
- 学习IOS的第五天
- C++学习第五天(字符串操作大汇总)
- JavaScript学习笔记之操作文件(第五天)
- 菜鸟:IOS 学习:磨难记 (第五天)
- ios学习第五天(一)对页面进行修改
- ios学习第五天(四)UILabel的使用
- ios学习第五天(五)UIButton的简单用法
- ios学习第五天(六)UIImageView的使用
- ios学习第五天(七)UI控件总结
- iOS学习——第五天
- iOS学习——第五天练习
- IOS 学习第五天 对象初始化
- iOS-学习笔记-UI-第五天
- iOS 第五天
- Java -Android 学习(第五天)
- Koa2 学习笔记(第五天)
- Qt 连接MySQL 驱动问题
- 类序列化问题-java.io.InvalidClassException
- 1015. Reversible Primes (20)
- 仿微信设置字体大小控件
- gcc编译时对’xxxx’未定义的引用问题
- ios学习第五天(三)View常用操作
- 三步学会Java Socket编程
- 线性代数笔记-1-方程组的几何解释
- MYSQL错误TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE的解决方案
- 要求输出从1到1000范围内所有与7相关数字的个数,与7相关的数字定义为,是7的倍数或者数字中含有7,比如17和71均含有‘7’。
- map,multimap,set,multiset
- 18-TCP 协议(迟到的 ACK—— Linux)
- POJ
- web项目,运行时不抛异常,调试时出现InvocationTargetException