abel 一般是作为接收信息用的,默认是不能更改的,而textFiled是可更改的,一般作为输入框,也可作为接收框 下面介绍一些创建的有关label和textFiled的属性用法 创建一个singleView,继承UITableView类 在.h文件中创建一个UILable和一个UITextFiled的对象 #import <UIKit/UIKit.h> @interface LYXViewController :UIViewController @property (nonatomic ,strong)UILabel * lable; @property (nonatomic ,strong)UITextField * textFile; @end //在.m文件中实现对象的属性 #import "LYXViewController.h" #import <QuartzCore/QuartzCore.h> @interface LYXViewController ()<UITextFieldDelegate> @end @implementation LYXViewController - (void)viewDidLoad { [superviewDidLoad]; //创建helloWord的接收框 self.lable = [[UILabelalloc]initWithFrame:CGRectMake(20,50,200,40)]; //设置lable的颜色 self.lable .backgroundColor = [UIColorbrownColor]; //给lable赋值 self.lable.text = @"Lee-YongXing @ Li-Yongxing"; //设置内容的字体、大小和加粗的方法 self.lable.font = [UIFontfontWithName:@"Arial"size:20.0f]; //字体加粗的方法 self.lable.font = [UIFont boldSystemFontOfSize:20.0f]; //字体的颜色 [self.lablesetTextColor:[UIColorredColor]]; //根据字体的大小,高度自适应 self.lable.adjustsFontSizeToFitWidth =YES; //内容的简单排版 //self.lable.textAlignment = UITextAlignmentCenter; // self.lable.textAlignment = UITextAlignmentLeft; // self.lable.textAlignment = UITextAlignmentRight; [self.lablesetTextAlignment:NSTextAlignmentCenter]; //内容的行数 self.lable.numberOfLines =0; //内容是否可以删改 // self.lable.enabled = NO; //设置label的透明度,里面的内容也会跟着透明度变化 //self.lable.alpha = 0.5; //设置lable的背景色为透明色 //self.lable.backgroundColor = [UIColor clearColor]; //设置背景图片,原则是,能不用UIImageView就不用 // self.lable.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"aa.jpg"]]; //如果输入内容过多,截去中间部分 self.lable.lineBreakMode = UILineBreakModeMiddleTruncation; //设置边角的弧度 self.lable.layer.cornerRadius = 10.0f; self.lable.layer.masksToBounds = YES; //设置lable的边框颜色 self.lable.layer.borderColor = [[UIColor blueColor] CGColor]; self.lable.layer.borderWidth = 1.0f; self.lable.layer.cornerRadius = 10.0f; self.lable.clipsToBounds = TRUE; [self.view addSubview:lable]; //设置阴影的颜色和阴影的偏移位置 self.lable.shadowColor = [UIColorredColor]; self.lable.shadowOffset =CGSizeMake(2.0,1.0); [self.viewaddSubview:self.lable ]; //-------创建一个输入框---------- self.textFile = [[UITextFieldalloc]initWithFrame:CGRectMake(20,120,200,40)]; //设置text的颜色 self.textFile.backgroundColor = [UIColorbrownColor]; //设置边角弧度 self.textFile.layer.cornerRadius = 10.0f; self.textFile.layer.masksToBounds = YES; //设置背景字,当输入字的时候被自动删除掉 self.textFile.placeholder = @"I LOVE YOU "; //设置边框的类型 self.textFile.borderStyle = UITextBorderStyleBezel; //键盘输入完成后时的推出按钮 self.textFile.returnKeyType = UIReturnKeyDone; //这个是文本的上下居中 self.textFile.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; //清除键,当输入完后想把内容全部删除,按这个按钮,全部删除 self.textFile.clearButtonMode = UITextFieldViewModeAlways; //实现代理方法 self.textFile.delegate =self; [self.viewaddSubview:self.textFile]; } //<----------------实现textFile代理方法-----------------> -(void)textFieldDidBeginEditing:(UITextField *)textField { } -(BOOL)textFieldShouldReturn:(UITextField *)textField { } -(void)textFieldDidEndEditing:(UITextField *)textField { } - (void)didReceiveMemoryWarning { [superdidReceiveMemoryWarning]; } @end