zoukankan      html  css  js  c++  java
  • UILabel的各种属性和方法

    转自:http://liulu200888an.blog.163.com/blog/static/3498972320121214208542/

    UILabel  *label1 = [[UILabel allocinitWithFrame:CGRectMake(20.020.0180.0,50.0)];

    UILabel  *label2 = [[UILabel alloc]initWithFrame:CGRectMake(20.080.0, 180.050.0)];     

    UILabel  *label3 = [[UILabel alloc]initWithFrame:CGRectMake(20.0140.0180.050.0)];    

    UILabel  *label4 = [[UILabel alloc]initWithFrame:CGRectMake(20.0200.0, 180.050.0)];

    //设置显示文字     

    label1.text = @"labelone";     

    label2.text = @"labeltwo";     

    label3.text = @"labelthree-labelthree-labelthree-labelthree-labelthree-labelthree";     

    label4.text = @"labelfour";

    //设置文字颜色  

    label1.textColor = [UIColor redColor];     

    label2.textColor = [UIColor blueColor]; 

    //设置字体:粗体,正常的是 SystemFontOfSize     

    label1.font = [UIFont boldSystemFontOfSize:30];

    //设置文字位置,居中还是靠左靠右     

    label1.textAlignment = UITextAlignmentRight;     

    label2.textAlignment = UITextAlignmentCenter;    

    //设置字体大小适应label宽度     

    label4.adjustsFontSizeToFitWidth = YES;   

    //设置label的行数     

    label3.numberOfLines = 2;

    //设置label的背景为透明

    label2.backgroundColor = [UIColor clearColor];

    //设置高亮     

    label4.highlighted = YES;     

    label4.highlightedTextColor = [UIColor orangeColor]; 

    //设置阴影     

    label1.shadowColor = [UIColor redColor];     

    label1.shadowOffset = CGSizeMake(1.0,1.0);  

    //设置是否能与用户进行交互     

    label3.userInteractionEnabled = YES;     

    //设置label中的文字是否可变,默认值是YES     

        label3.enabled = NO;

    //设置文字过长时的显示格式     

        label3.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间     

    //  typedef enum {     

    //      UILineBreakModeWordWrap = 0,     

    //      UILineBreakModeCharacterWrap,     

    //      UILineBreakModeClip,//截去多余部分     

    //      UILineBreakModeHeadTruncation,//截去头部     

    //      UILineBreakModeTailTruncation,//截去尾部     

    //      UILineBreakModeMiddleTruncation,//截去中间     

    //  } UILineBreakMode;     

        //如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为     

        label4.baselineAdjustment = UIBaselineAdjustmentNone;     

    //  typedef enum {     

    //      UIBaselineAdjustmentAlignBaselines,     

    //      UIBaselineAdjustmentAlignCenters,     

    //      UIBaselineAdjustmentNone,     

    //  } UIBaselineAdjustment;     

        [self.view addSubview:label1];     

        [self.view addSubview:label2];     

        [self.view addSubview:label3];     

        [self.view addSubview:label4]; 

        [label1 release];     

        [label2 release];     

        [label3 release];     

        [label4 release];

    //点击label1时显示白色(是点击label1,不是点击label.Text)

    -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

    {

        [label1 setTextColor:[UIColor whiteColor]];

    }

    -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

    {

        [label1 setTextColor:[UIColor blackColor]];

        UITouch *touch = [touches anyObject];

    //    CGPoint points = [touch locationInView:<#(UIView *)#>];

        CGPoint points = [touch locationInView:label];

        if (points.x >= label.frame.origin.x && points.y >= label.frame.origin.x && points.x <= label.frame.size.width && points.y <= label.frame.size.height)

        {

    //        [delegate myLabel:self touchesWtihTag:self.tag];

        }

    }

  • 相关阅读:
    重新认识布局:html和body元素
    重新认识布局:3d空间中的css盒子
    重新认识布局:百分比单位
    重新认识布局:标准流,浮动,定位的关系
    Redis(1.7)Redis高可用架构与数据库交互(理论篇)
    C++: 模块定义文件声明(.def)的使用
    HttpListener supports SSL only for localhost? install certificate
    跨域请求引起的 OPTIONS request
    html 浏览器自动加上 标签的详解
    c# HttpServer 的使用
  • 原文地址:https://www.cnblogs.com/LCGIS/p/3309964.html
Copyright © 2011-2022 走看看