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

        }

    }

  • 相关阅读:
    【LeetCode】46. 全排列(回溯)
    [P2894][USACO08FEB] 酒店Hotel (线段树+懒标记下传)
    [P2680][NOIP2015T6] 运输计划 (LCA+树上差分+二分)
    静态主席树学习笔记
    [P1941][NOIP2014T3] 飞扬的小鸟 (0/1背包+完全背包)
    [P1084][NOIP2012T6] 疫情控制 (二分+贪心+LCA)
    [P3959][NOIP2017T5] 宝藏 (状压DP+DFS)
    [P2679][NOIP2015T5] 子串 (DP+滚动数组)
    [P1314][NOIP2011T5] 聪明的质检员 (二分+前缀和)
    [P1966][NOIP2013T2] 火柴排队 (求逆序对+归并排序/树状数组)
  • 原文地址:https://www.cnblogs.com/LCGIS/p/3309964.html
Copyright © 2011-2022 走看看