欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

IOS开发(11)之UILabel

来源: 开发者 投稿于  被查看 49096 次 评论:132

IOS开发(11)之UILabel


1 前言
UILabel可以显示给用户静态文本,并且控制文本的字体和颜色,今天我们来学习一下UILabel。

2 代码实例
ZYViewController.h:


[plain]
#import <UIKit/UIKit.h> 
 
@interface ZYViewController : UIViewController 
 
@property(nonatomic,strong) UILabel *myLabel; 
 
@end 

#import <UIKit/UIKit.h>

@interface ZYViewController : UIViewController

@property(nonatomic,strong) UILabel *myLabel;

@end


ZYViewController.m:


[plain]
@synthesize myLabel; 
 
- (void)viewDidLoad 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    self.view.backgroundColor = [UIColor whiteColor]; 
//    CGRect labelFrame = CGRectMake(0.0f, 0.0f, 100.0f, 23.0f); 
    CGRect labelFrame = CGRectMake(0.0f, 0.0f, 100.0f, 50.0f); 
    self.myLabel = [[UILabel alloc] initWithFrame:labelFrame]; 
    self.myLabel.numberOfLines = 3;//分三行 
    self.myLabel.text = @"Archy is Studying IOS 5 Programming";//label的文字 
    self.myLabel.font = [UIFont boldSystemFontOfSize:14.0f];//字体样式 
    self.myLabel.center = self.view.center;//UILabel控件居中 
    [self.view addSubview:self.myLabel]; 
     

@synthesize myLabel;

- (void)viewDidLoad
{
    [super viewDidLoad];
 // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
//    CGRect labelFrame = CGRectMake(0.0f, 0.0f, 100.0f, 23.0f);
    CGRect labelFrame = CGRectMake(0.0f, 0.0f, 100.0f, 50.0f);
    self.myLabel = [[UILabel alloc] initWithFrame:labelFrame];
    self.myLabel.numberOfLines = 3;//分三行
    self.myLabel.text = @"Archy is Studying IOS 5 Programming";//label的文字
    self.myLabel.font = [UIFont boldSystemFontOfSize:14.0f];//字体样式
    self.myLabel.center = self.view.center;//UILabel控件居中
    [self.view addSubview:self.myLabel];
   
}
运行结果:

 \
 


 

相关文章

    暂无相关文章

用户评论