UI_UILabel(标签)

来源:互联网 发布:阿里云快照恢复 编辑:程序博客网 时间:2024/06/05 03:33

UILabel


"AppDelegate.m"


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

    self.window = [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];



    //创建label

   UILabel*newlabel = [[UILabelalloc]initWithFrame:CGRectMake(100, 100, 100, 80)];//window的位置

    

    //设置背景颜色

    newlabel.backgroundColor = [UIColorblueColor];

 

    //添加文本

   newlabel.text=@"用户名";

    

    //设置边框

   newlabel.layer.borderWidth= 0.5;//边框粗细

    

    //设置圆角

   newlabel.layer.cornerRadius= 10;

    

    //隐藏多余的部分

   newlabel.layer.masksToBounds =YES;

    

    //设置文本的对齐方式

    newlabel.textAlignment =NSTextAlignmentCenter;

    

//    newlabel.textColor = [UIColor purpleColor];

//    newlabel.numberOfLines = 3; //行数

    //label自己去根据文字的多少来适应对应的宽度

   [newlabelsizeToFit];

    //设置一个断行模式

    

    newlabel.lineBreakMode =NSLineBreakByTruncatingMiddle;

    

    //设置文字大小

    newlabel.font = [UIFontsystemFontOfSize:20];

    

    //设置阴影的颜色

    newlabel.shadowColor = [UIColoryellowColor];

    

    //设置阴影的偏移量

//    newlabel.shadowOffset = CGSizeMake(10, 10);

    

    [self.windowaddSubview:newlabel];//一定要先把Label先添加到window,Subview是一个数组,会使newlabel的引用计数+1

    

   [newlabelrelease];


  //第一个参数:NSTimerInterval时间间隔,设置每次执行的时间

    //第二个参数:设置动作的执行人,一般是self

    //第三个参数:设置执行的方法

    //第五个参数:是否重复

    [NSTimer scheduledTimerWithTimeInterval:3 target:selfselector:@selector(test)userInfo:nilrepeats:YES];


    [_window release];

    return YES;

}


- (void)test

{

    NSLog(@"我是测试计时器");

}



0 0
原创粉丝点击