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];

        }

    }

  • 相关阅读:
    javascript内存泄漏
    闭包
    JavaScript 数组(Array)对象
    什么是跨域?跨域请求资源的方法有哪些?
    理解闭包
    比较typeof与instanceof
    js 字符串操作函数
    js去除字符串空格
    Thematic002.字符串专题
    Thematic001.数论专题
  • 原文地址:https://www.cnblogs.com/LCGIS/p/3309964.html
Copyright © 2011-2022 走看看