码迷,mamicode.com
首页 > 其他好文 > 详细

UILabel

时间:2015-11-22 17:19:53      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:

    //UILabel->UIView

    /*

     1、实例化

     2、属性

     3、添加到父视图上

     */

    //实例化

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 280, 30)];

    

    //属性

    label.backgroundColor = [UIColor redColor];

    label.alpha = 1.0;

    label.hidden = NO;

    

    //自己特有的属性

    //展示文本文字的属性:text

    label.text = @"不要说再见、さようならは言わないで";

    //文本文字的颜色:默认黑色:textColor

    label.textColor = [UIColor blueColor];

    //设置字号:font

    label.font = [UIFont systemFontOfSize:18.0];

    //设置字号(带有斜体效果)italicSystemFontOfSize

//    label.font = [UIFont italicSystemFontOfSize:18.0];

    //设置字号(带有加粗效果)boldSystemFontOfSize

    label.font = [UIFont boldSystemFontOfSize:18.0];

    //对齐方式:textAlignment

    /*

     1NSTextAlignmentCenter  居中

     2NSTextAlignmentLeft   左对齐,默认

     3NSTextAlignmentRight  右对齐

     */

    label.textAlignment = NSTextAlignmentLeft;

    //设置行数:numberOfLines  写大于0的数:写几出现几行;0:自动换行

    label.numberOfLines = 0;

    //自适应文字大小:adjustsFontSizeToFitWidth

//    label.adjustsFontSizeToFitWidth = YES;

    //自适应label的高度

    [label sizeToFit];

    

    //文字的阴影效果

    label.shadowColor = [UIColor whiteColor];

    //阴影的偏移量

    label.shadowOffset = CGSizeMake(5, 5);

    

    //找到整体的字体族

    NSArray *familyName = [UIFont familyNames];

    for (NSString *name in familyName) {

        //找到字体族里面对应的字体名字

        NSArray *fontName = [UIFont fontNamesForFamilyName:name];

        for (NSString *font in fontName) {

            //找到确定的字体名字

            NSLog(@"%@",font);

        }

    }

    //添加到父视图上面

    [self.window addSubview:label];

    

    

    //创建第二个UILabel,用具体的字体来初始化

    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(20, 220, 280, 80)];

    label2.backgroundColor = [UIColor cyanColor];

    label2.text = @"hello hi everyOne";

    label2.textColor = [UIColor redColor];

    label2.textAlignment = NSTextAlignmentCenter;

    

    //用确切的字体设置font

    label2.font = [UIFont fontWithName:@"Thonburi" size:18.0];

    

    [self.window addSubview:label2];

    

    

    //获取整个屏幕的宽

    CGFloat width = self.window.frame.size.width;

    //获取整个屏幕的高

    CGFloat height = self.window.frame.size.height;

    NSLog(@"%f   %f",width,height);

UILabel

标签:

原文地址:http://www.cnblogs.com/hyuganatsu/p/UILabel.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!