zoukankan      html  css  js  c++  java
  • UILabel的各种属性与方法的使用[转]

      1 #import "LabelTestViewController.h"   
      2 @implementation LabelTestViewController   
      3 /*  
      4 Accessing the Text Attributes  
      5     text  property    
      6     font  property    
      7     textColor  property    
      8     textAlignment  property    
      9     lineBreakMode  property      
     10     enabled  property    
     11 Sizing the Label’s Text  
     12     adjustsFontSizeToFitWidth  property    
     13     baselineAdjustment  property    
     14     minimumFontSize  property   无例  
     15     numberOfLines  property    
     16 Managing Highlight Values  
     17     highlightedTextColor  property    
     18     highlighted  property    
     19 Drawing a Shadow  
     20     shadowColor  property    
     21     shadowOffset  property    
     22 Drawing and Positioning Overrides  
     23     – textRectForBounds:limitedToNumberOfLines: 无例   
     24     – drawTextInRect:  无例  
     25 Setting and Getting Attributes  
     26     userInteractionEnabled  property    
     27 */  
     28 
     29 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.   
     30 - (void)viewDidLoad {   
     31     UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 20.0, 200.0, 50.0)];   
     32     UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 80.0, 200.0, 50.0)];   
     33     UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 140.0, 200.0, 50.0)];   
     34     UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 200.0, 200.0, 50.0)];   
     35     UILabel *label5 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 260.0, 200.0, 50.0)];   
     36     UILabel *label6 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 320.0, 200.0, 50.0)];   
     37     UILabel *label7 = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 380.0, 200.0, 50.0)];   
     38 
     39     //设置显示文字   
     40     label1.text = @"label1";   
     41     label2.text = @"label2";   
     42     label3.text = @"label3--label3--label3--label3--label3--label3--label3--label3--label3--label3--label3--";   
     43     label4.text = @"label4--label4--label4--label4--";   
     44     label5.text = @"label5--label5--label5--label5--label5--label5--";   
     45     label6.text = @"label6";   
     46     label7.text = @"label7";   
     47 
     48     //设置字体   
     49     label1.font = [UIFont boldSystemFontOfSize:20];   
     50 
     51     //设置文字颜色   
     52     label1.textColor = [UIColor orangeColor];   
     53     label2.textColor = [UIColor purpleColor];   
     54 
     55     //设置文字位置   
     56     label1.textAlignment = UITextAlignmentRight;   
     57     label2.textAlignment = UITextAlignmentCenter;   
     58     //设置字体大小适应label宽度   
     59     label4.adjustsFontSizeToFitWidth = YES;   
     60 
     61     //设置label的行数   
     62     label5.numberOfLines = 2;   
     63 
     64     //设置高亮   
     65     label6.highlighted = YES;   
     66     label6.highlightedTextColor = [UIColor orangeColor];   
     67 
     68     //设置阴影   
     69     label7.shadowColor = [UIColor redColor];   
     70     label7.shadowOffset = CGSizeMake(1.0,1.0);   
     71 
     72     //设置是否能与用户进行交互   
     73     label7.userInteractionEnabled = YES;   
     74 
     75     //设置label中的文字是否可变,默认值是YES   
     76     label3.enabled = NO;   
     77 
     78     //设置文字过长时的显示格式   
     79     label3.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间   
     80 //  typedef enum {   
     81 //      UILineBreakModeWordWrap = 0,   
     82 //      UILineBreakModeCharacterWrap,   
     83 //      UILineBreakModeClip,//截去多余部分   
     84 //      UILineBreakModeHeadTruncation,//截去头部   
     85 //      UILineBreakModeTailTruncation,//截去尾部   
     86 //      UILineBreakModeMiddleTruncation,//截去中间   
     87 //  } UILineBreakMode;   
     88 
     89     //如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为   
     90     label4.baselineAdjustment = UIBaselineAdjustmentNone;   
     91 //  typedef enum {   
     92 //      UIBaselineAdjustmentAlignBaselines,   
     93 //      UIBaselineAdjustmentAlignCenters,   
     94 //      UIBaselineAdjustmentNone,   
     95 //  } UIBaselineAdjustment;   
     96 
     97 
     98     [self.view addSubview:label1];   
     99     [self.view addSubview:label2];   
    100     [self.view addSubview:label3];   
    101     [self.view addSubview:label4];   
    102     [self.view addSubview:label5];   
    103     [self.view addSubview:label6];   
    104     [self.view addSubview:label7];   
    105 
    106     [label1 release];   
    107     [label2 release];   
    108     [label3 release];   
    109     [label4 release];   
    110     [label5 release];   
    111     [label6 release];   
    112     [label7 release];   
    113 
    114     [super viewDidLoad];   
    115 }   
    116 
    117 /*  
    118 // Override to allow orientations other than the default portrait orientation.  
    119 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
    120     // Return YES for supported orientations  
    121     return (interfaceOrientation == UIInterfaceOrientationPortrait);  
    122 }  
    123 */  
    124 - (void)didReceiveMemoryWarning {   
    125     // Releases the view if it doesn't have a superview.   
    126     [super didReceiveMemoryWarning];   
    127 
    128     // Release any cached data, images, etc that aren't in use.   
    129 }   
    130 - (void)viewDidUnload {   
    131     // Release any retained subviews of the main view.   
    132     // e.g. self.myOutlet = nil;   
    133 }   
    134 
    135 - (void)dealloc {   
    136     [super dealloc];   
    137 }   
    138 @end
    View Code

    转帖来源于此:http://wiki.eoe.cn/page/iOS_blog_page_91033.html

    iOS代码传参调用系统自带应用  :

    如:调用电话功能、调用safar打开网页等

    http://blog.163.com/cz_jdton/blog/static/92732504201292310161928/

  • 相关阅读:
    jQuery.getJSON的缓存问题的解决办法
    MFC Tab Control控件的详细使用
    JavaScript 闭包深入理解(closure)
    STL中sort函数用法简介
    STL中qsort的七种用法
    学习Javascript闭包(Closure)
    使用 Visual Studio 分析器找出应用程序瓶颈
    各种语言性能测试工具一览表
    Javascript 链式作用域
    MessageBox、::MessageBox 、AfxMessageBox三者的区别 .
  • 原文地址:https://www.cnblogs.com/chenxiangxi/p/3645305.html
Copyright © 2011-2022 走看看