iOS_uilabel

来源:互联网 发布:云计算与服务工程 编辑:程序博客网 时间:2024/06/13 21:54

 //创建uilabel

    UILabel *label1 = [[UILabelalloc] initWithFrame:CGRectMake(20,80, 280,80)];

    //设置背景色

    label1.backgroundColor = [UIColorgrayColor];

    //设置tag

    label1.tag =91;

    //设置标签文本

    label1.text =@"CCBASE.NET!";

    //设置标签文本字体和字体大小

    label1.font = [UIFontsystemFontOfSize:30];

    //设置文本对齐方式

    label1.textAlignment =NSTextAlignmentLeft;

    //文本对齐方式有以下三种

    //typedef enum {

    //    NSTextAlignmentLeft = 0,左对齐

    //    NSTextAlignmentCenter,居中对齐

    //    NSTextAlignmentRight,右对齐

    //} UITextAlignment;

    //文本颜色

    label1.textColor = [UIColorblueColor];

    //超出label边界文字的截取方式

    //文本文字自适应大小

    label1.adjustsFontSizeToFitWidth =YES;

    //adjustsFontSizeToFitWidth=YES时候,如果文本font要缩小时

    //baselineAdjustment这个值控制文本的基线位置,只有文本行数为1是有效

    label1.baselineAdjustment =UIBaselineAdjustmentAlignCenters;

    //文本最多行数,为0时没有最大行数限制

    label1.numberOfLines =1;

    //最小字体,行数为1时有效,默认为0.0

    //文本高亮

    label1.highlighted =YES;

    //文本是否可变

    label1.enabled =YES;

    //去掉label背景色

    //label1.backgroundColor = [UIColor clearColor];

    //文本阴影颜色

    label1.shadowColor = [UIColorredColor];

    //阴影大小

    label1.shadowOffset =CGSizeMake(1.0,1.0);

    //是否能与用户交互

    label1.userInteractionEnabled =YES;

    [self.viewaddSubview:label1];

0 0