IOS开发UI-------UIView(视图)
2016-01-18 16:03
465 查看
UIView
特别注意:UIView是所有控件的父类
以下是view得各种属性设置(背景颜色,tag值,设置圆角,位于此view之下的view是否遮盖,边框大小,边框颜色)
设置View的大小位置颜色
这里需要提及一个View的属性userInteractionEnabled
以下是用上面的View做得一个小UI
Button实现的方法在这里
特别注意:UIView是所有控件的父类
以下是view得各种属性设置(背景颜色,tag值,设置圆角,位于此view之下的view是否遮盖,边框大小,边框颜色)
UIView *aView = [[UIView alloc]initWithFrame:CGRectMake(10, 50, 100, 100)]; //给视图添加背景颜色 aView.backgroundColor = [UIColor redColor]; //每一个View都有一个tag的属性 aView.tag = 1000; //设置圆角 aView.layer.cornerRadius = 15; //告诉layer将位于它之下的layer都遮盖住 aView.layer.masksToBounds = YES; //设置边框大小 aView.layer.borderWidth = 3; //设置边框颜色 aView.layer.borderColor = [UIColor greenColor].CGColor; [self.view addSubview:aView]; /* 理解子视图和父视图得概念 UIView *superview = aView.superview; NSArray *subViewARR = aView.subviews; */ //每个视图都有添加子视图的方法:addSubview: // [aView addSubview:<#(nonnull UIView *)#>]
设置View的大小位置颜色
UIView *Bview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)]; Bview.backgroundColor = [UIColor cyanColor]; /* 关于视图的位置:UIView类给了三个属性:frame;bounds;center; frame和bounds的区别 frame 使有参照物的,参考父视图的左上角 bounds使参考它自己 */ NSLog(@"aview.frame = %@",[NSValue valueWithCGRect:aView.frame]); NSLog(@"aview.bounds = %@",[NSValue valueWithCGRect:aView.bounds]); NSLog(@"aView.center = %@",[NSValue valueWithCGPoint:aView.center]);
这里需要提及一个View的属性userInteractionEnabled
/* //一个BOOL值,决定是否用户触发的事件被该视图对象忽略和把该视图对象从事件相应队列中移除 //UIImageView 会默认userInteractionEnabled为NO,即不能点击; */ aView.userInteractionEnabled = YES; UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"7`TY]FD{UB3TXDMCR)BAS(P.jpg"]]; image.frame = CGRectMake(150, 200, 200, 300); [self.view addSubview:image];
以下是用上面的View做得一个小UI
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setTitle:@"点击wo" forState:UIControlStateNormal]; // [button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal]; button.backgroundColor = [UIColor orangeColor]; button.frame = CGRectMake(10, 200, 100, 100); [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; _flag = YES;//这是一个全局变量
Button实现的方法在这里
-(void)buttonAction:(UIButton *)sender{ NSLog(@"点击了一下"); UIView *newView = [self.view viewWithTag:1000]; _flag =!_flag; newView.backgroundColor = _flag?[UIColor redColor]:[UIColor yellowColor]; if (!_flag) { //此方法是将VIEW移动(持续动画) [UIView animateWithDuration:2.0 animations:^{ //(移动到指定的位置) newView.frame = CGRectMake(200, 50, 120, 120); }]; }else{ [UIView animateWithDuration:2.0 animations:^{ newView.frame = CGRectMake(10, 50, 120, 120); }]; } }
相关文章推荐
- UIImage 注意事项
- 【从零学习经典算法系列】分治策略实例——高速排序(QuickSort)
- 快排Quick Sort到底有多快?
- You attempted an operation that requires PV drivers to be installed on the VM.
- [iOS]关于状态栏(UIStatusBar)的若干问题
- UESTC--1256
- Divide and conquer:Dropping tests(POJ 2976)
- 果冻回弹效果 拉刷新效果 UIBezierPath
- UItableView搜索和全部删除
- UICollectionView的基本使用
- UITableView 分割线贴近左端屏幕开始
- 学习笔记:关于segue
- NGUI 相片循环滚动效果
- UI控件RecyclerView浅析
- 【django】request
- LeetCode Range Sum Query - Mutable
- UILabel根据文字计算高度在UItableview中的应用
- 《iOS Human Interface Guidelines》——HealthKit
- UIpickerView获得选中值
- XML hexadecimal value 0x__, is an invalid character