zoukankan      html  css  js  c++  java
  • 什么是UILabel

    UILabel极其常用,功能比较专一:显示文字

    UILabel的常见属性

    @property(nonatomic,copy) NSString *text;
    显示的文字

    @property(nonatomic,retain) UIFont *font;
    字体

    @property(nonatomic,retain) UIColor *textColor;
    文字颜色

    @property(nonatomic) NSTextAlignment textAlignment;
    对齐模式(比如左对齐、居中对齐、右对齐)

    @property(nonatomic) NSInteger numberOfLines;
    文字行数

    @property(nonatomic) NSLineBreakMode lineBreakMode;
    换行模式

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        // 1.1 创建UILabel对象
        UILabel *label = [[UILabel alloc] init];
        
        // 1.2 设置frame
        label.frame = CGRectMake(100, 100, 202, 175);
        
        // 1.3 设置背景颜色
        label.backgroundColor = [UIColor redColor];
        
        // 1.4 设置文字
        label.text = @"da shen XX期最牛逼!!!!da shen da shen da shen da shen da shen ";
        
        // 1.5 居中
        label.textAlignment = NSTextAlignmentCenter;
        
        // 1.6 设置字体大小
        label.font = [UIFont systemFontOfSize:20.f];
        label.font = [UIFont boldSystemFontOfSize:25.f];
        label.font = [UIFont italicSystemFontOfSize:20.f];
        
        // 1.7 设置文字的颜色
        label.textColor = [UIColor whiteColor];
        
        // 1.8 设置阴影(默认是有值)
        label.shadowColor = [UIColor blackColor];
        label.shadowOffset = CGSizeMake(-2, 1);
        
        // 1.9 设置行数(0:自动换行)
        label.numberOfLines = 1;
        
        // 1.10 显示模式
        label.lineBreakMode =  NSLineBreakByTruncatingHead;
        
        /*
         NSLineBreakByWordWrapping = 0,  // 单词包裹,换行的时候会以一个单词换行
         NSLineBreakByCharWrapping,        // 字符包裹换行,换行的时候会以一个字符换行
         NSLineBreakByClipping,        // 裁剪超出的内容
         NSLineBreakByTruncatingHead,    // 一行中头部省略(注意:numberOfLines要为1): "...wxyz"
         NSLineBreakByTruncatingTail,    // 一行中尾部省略: "abcd..."
         NSLineBreakByTruncatingMiddle    // 一行中中间部省略:  "ab...yz"
         */
        
        
        // 2.0 添加到控制器的view中
        [self.view addSubview:label];
    }
  • 相关阅读:
    BZOJ3790 : 神奇项链
    BZOJ3630 : [JLOI2014]镜面通道
    BZOJ3738 : [Ontak2013]Kapitał
    个人总结
    mac 下的 top 命令
    去掉Xcode源码末尾的空格
    让UILabel的文字顶部对齐
    使用RBTool自动提交code review请求
    不要在init和dealloc函数中使用accessor
    将textField编辑完内容作为参数发送请求
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6034348.html
Copyright © 2011-2022 走看看