iOS02 UILable和UITextFiled的自定义

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

 

转载于:https://www.cnblogs.com/ytmaylover/p/5050127.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值