UIView基础
来源:互联网 发布:米尔格伦实验 知乎 编辑:程序博客网 时间:2024/05/22 15:11
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIView *myview=[[UIView alloc]init]; myview.frame=CGRectMake(40, 20, 200, 200); myview.backgroundColor=[UIColor blueColor]; [self.view addSubview:myview]; NSLog(@"x:%f,t:%f,w:%f,h:%f.",myview.frame.origin.x,myview.frame.origin.y ,myview.frame.size.width,myview.frame.size.height); NSLog(@"x:%f,t:%f,w:%f,h:%f.",myview.bounds.origin.x,myview.bounds.origin.y ,myview.bounds.size.width,myview.bounds.size.height); NSLog(@"x:%f,t:%f.",myview.center.x,myview.center.y); //父式图 UIView *superview=myview.superview; superview.backgroundColor=[UIColor greenColor]; UIView *view2=[[UIView alloc]init]; view2.frame=CGRectMake(10, 20, 20, 20); view2.backgroundColor=[UIColor yellowColor]; view2.tag=2; [myview addSubview:view2]; UIView *view3=[[UIView alloc]init]; view3.frame=CGRectMake(5, 30, 50, 40); view3.tag=3; view3.backgroundColor=[UIColor purpleColor]; [myview addSubview:view3]; //将子视图加入数组中进行遍历 NSArray *mysubviews=myview.subviews; for (UIView *view in mysubviews) { if (view.tag==2) { view.backgroundColor=[UIColor greenColor]; } view3.backgroundColor=[UIColor yellowColor]; } //使用tag进行选择 viewwithtag UIView *sub2view=[myview viewWithTag:3]; sub2view.backgroundColor=[UIColor grayColor]; //交换两个层式图 [myview exchangeSubviewAtIndex:2 withSubviewAtIndex:3]; UIView *view4=[[UIView alloc]init]; view4.frame=CGRectMake(10, 20, 20, 20); view4.backgroundColor=[UIColor blackColor]; //[myview insertSubview:view4 atIndex:2]; // [myview insertSubview:view4 belowSubview:view2]; //[myview bringSubviewToFront:view2]; [myview sendSubviewToBack:view3]; UIView *backview=[[UIView alloc]init]; backview.frame=CGRectMake([UIScreen mainScreen].bounds.size.width/2-25, 400, 50, 50); backview.tag=1001; backview.backgroundColor=[UIColor orangeColor]; [self.view addSubview:backview]; //准许子视图自适应 backview.autoresizesSubviews=YES; UIView *topview=[[UIView alloc]init]; topview.frame=CGRectMake(10, 10, 30, 30); topview.backgroundColor=[UIColor yellowColor]; //子视图自适应 topview.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin; /* 跟随那一边进行变化 UIViewAutoresizingFlexibleLeftMargin; UIViewAutoresizingFlexibleHeight; UIViewAutoresizingFlexibleTopMargin; */ [backview addSubview:topview]; //button UIButton *btn=[UIButton buttonWithType:UIButtonTypeSystem]; btn.frame=CGRectMake(10, 550, 355, 30); btn.backgroundColor=[UIColor blackColor]; [btn addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}//button点击事件-(void)btnclick{ UIView *view=[self.view viewWithTag:1001]; view.frame=CGRectMake(view.frame.origin.x-5, view.frame.origin.y-5, view.frame.size.width+10, view.frame.size.height+10);}@end
0 0
- UIView 基础
- UIView基础
- UIView基础
- UI基础UIWindow、UIView
- UIView之ContentMode基础
- UIView 基础动画
- iOS基础UIView
- UI基础之 UIview
- iOS 基础 - UIView
- UIView基础篇
- UI基础类 UIView
- UI基础-02-UIView
- UIView基础笔记
- UIView 基础动画
- IOS疯狂基础之UIView
- UI基础-UIView及其子类
- iOS UI UIView基础概况
- 有关UIView、subview的几个基础知识点
- 设置Swing全局字体
- java 怎样读取指定行数的信息
- CheckBox_选择框控件(2)
- GP数据库系统管理语句
- LeetCode题解——Power of Three
- UIView基础
- 编译hadoop1.2.1 eclipse插件
- Mysql inner join on用法例子
- iterator迭代器
- BZOJ 1038 ZJOI2008 瞭望塔 半平面交
- lwip tcp_output源码解析
- GP数据库开发语句
- 菜鸟学python(5) while语句
- 浅谈inline-block及解决空白间距