21.View,Label,Button,TextField
来源:互联网 发布:部落冲突九本满防数据 编辑:程序博客网 时间:2024/04/30 10:12
1.UIView
//1.创建一个UIView的对象UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];//2.view1设置背景颜色view1.backgroundColor = [UIColor cyanColor];//3.把试图贴到窗口上[self.window addSubview:view1];//4.释放[view1 release];//试图添加到父视图的数组之后,数组会增加视图的引用计数,相应的也就可在添加之后对视图进行释放//视图的坐标起始位置在父视图的左上角,一个视图可以有多个子视图,但是一个视图只能有一个父视图//先创建的先添加到superview的视图会在层级关系的最下面,通过父视图来管理它身上所有的子视图的层级关系[self.window bringSubviewToFront:view2];//父视图把指定的视图放在最上面/下面[self.window sendSubviewToBack:view2];//透明度view2.alpha = 0.5;//tag不能是0,不能重复view3.tag = 100;//通过tag找到对应的viewUIView *tempView = [self.window viewWithTag:100];
2.UILabel
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 40, 150, 200)];label.backgroundColor = [UIColor orangeColor];[self.window addSubview:label];//设置文本内容label.text = @"fafdfasdfdasfdsa]";//设置行数,默认是一行,设置为0是行数的最大值label.numberOfLines = 3;//让文本自己去适应label的尺寸,显示全部内容[label sizeToFit];//--->**//文本的对齐方式(默认左对齐)label.textAlignment = NSTextAlignmentCenter;//断行模式label.lineBreakMode = NSLineBreakByTruncatingMiddle;//文本内容的颜色label.textColor = [UIColor redColor];//阴影颜色label.shadowColor = [UIColor redColor];//阴影大小label.shadowOffset = CGSizeMake(1, 2);//设置边框label.layer.borderWidth = 1;//--->**//设置圆角label.layer.cornerRadius = 5;//--->**//隐藏多余的部分label.layer.masksToBounds = YES;//--->**//字体大小label.font = [UIFont systemFontOfSize:20];//center可以改变视图的位置label.center = CGPointMake(150, 150);[label release];
3.UIButton
//用button自己的便利构造器的方式来创建对象UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];//指定button的位置和大小button.frame = CGRectMake(30, 50, 100, 30);//设置背景颜色button.backgroundColor = [UIColor redColor];//给button设置标题[button setTitle:@"点我啊" forState:UIControlStateNormal];[button setTitle:@"hehe" forState:UIControlStateHighlighted];//设置字体大小button.titleLabel.font = [UIFont systemFontOfSize:18];//--->**//设置一下边框和圆角,隐藏多余的部分button.layer.borderWidth = 0.1;//--->**button.layer.cornerRadius = 10;//--->**button.layer.masksToBounds = YES;//--->**[self.window addSubview:button];//button不用release//--->**//--->**//--->**UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];button1.frame = CGRectMake(40, 40, 30, 30);//给button设置背景图片,图片大小由frame决定,填满整个frame[button1 setBackgroundImage:[UIImage imageNamed:@"checked"] forState:UIControlStateNormal];[self.window addSubview:button1];[button1 addTarget:self action:@selector(chageImage:) forControlEvents:UIControlEventTouchUpInside];self.isClick = NO;//isClick为BOOL类型的属性UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];button2.frame = CGRectMake(120, 40, 51, 24);//如果想使用setImage设置图片的话,button的类型要调整成custom,setImage方法不会把图片放大成按钮大小,但是如果按钮的frame比图片小,则会缩小成按钮大小[button2 setImage:[UIImage imageNamed:@"BtnOn"] forState:UIControlStateNormal];button2.tag = 100;[self.window addSubview:button2];self.isSelected = YES;//isSelected为BOOL类型的属性//点击方法 button最重要的方法[button2 addTarget:self action:@selector(chgngePic:) forControlEvents:UIControlEventTouchUpInside];- (void)chageImage:(UIButton *)button{ if (self.isClick) { [button setBackgroundImage:[UIImage imageNamed:@"checked"] forState:UIControlStateNormal]; } else{ [button setBackgroundImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal]; } self.isClick = !self.isClick;}- (void)chgngePic:(UIButton *)button//button为传送过来的一个参数{ if (self.isSelected) { [button setImage:[UIImage imageNamed:@"BtnOff"] forState:UIControlStateNormal]; } else{ [button setImage:[UIImage imageNamed:@"BtnOn"] forState:UIControlStateNormal]; } self.isSelected = !self.isSelected;}
4.UITextField
//输入框UITextFiledUITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(40, 60, 200, 40)];textField.backgroundColor = [UIColor redColor];//加上圆角和边框,隐藏多余的部分textField.layer.borderWidth = 1;textField.layer.cornerRadius = 5;label.layer.masksToBounds = YES;//UITextField系统提供的属性textField.borderStyle = UITextBorderStyleRoundedRect;textField.text = @"zhangsan";textField.textColor = [UIColor greenColor];textField.textAlignment = NSTextAlignmentCenter;textField.font = [UIFont systemFontOfSize:20];//占位符,当输入是消失textField.placeholder = @"请输入密码";//密文输入textField.secureTextEntry = YES;textField.tag = 100;//textField的清除buttontextField.clearButtonMode = UITextFieldViewModeWhileEditing;//改变键盘的类型textField.returnKeyType = UIReturnKeySearch;textField.keyboardType = UIKeyboardTypeNumberPad;[self.window addSubview:textField];[textField release];UIView *view = [[UIView alloc] initWithFrame:CGRectMake(40, 40, 40, 40)];view.backgroundColor = [UIColor greenColor];//弹出一个自定义视图,默认是键盘textField.inputView = view;//给键盘添加一个辅助视图textField.inputAccessoryView = view;//给textfield设置代理人textField.delegate = self;
0 0
- 21.View,Label,Button,TextField
- iOS 中view label button textField 随机颜色
- 自定义View--Label + TextField
- label textField button 一些用法
- Label Button和textfield组合
- 用Button连接TextField和Label
- UI创建基本的Label TextField Button
- 1、Button、Label和Textfield的交互
- IOS学习四:基础控件Label,textfield,button等使用
- Java 好看的label-textfield(-button)布局
- Xcode控件使用笔记一:label、Button、slider 、switch、imageView、toolBar、TextField
- iPhone开发 Label,button,view,window控件的添加
- xib 控件设置圆角 label button view 等
- label textField textview
- Extjs textfield 空白label
- button、dateField、textField
- 黑马程序员——IOS学习四:基础控件Label,textfield,button等使用——黑马 ios 技术博客
- 【学习7】Label与TextField
- POJ1190生日蛋糕题解
- POJ 1321--棋盘问题【DFS】
- HDU5119.Happy Matt Friends
- H.264码流结构
- EQueue - 一个C#写的开源分布式消息队列的总体介绍
- 21.View,Label,Button,TextField
- windows下解决快捷键失效的万能方法
- hdu3768Shopping 最短路+暴力
- ios 给label添加横线
- Elasticsearch+Logstash+Kibana配置
- POJ 2452 (RMQ + 二分)
- EQueue - 详细谈一下消息持久化以及消息堆积的设计
- UE4与WEB服务器交互(json)
- android 占位符使用