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];
    }
  • 相关阅读:
    1136 A Delayed Palindrome (algorithm reverse(ans.begin,ans.end))
    1141 PAT Ranking of Institutions PAT甲级
    最近点对 (迭代器访问数据)
    1146 Topological Order PAT 甲级
    1151 1151 LCA in a Binary Tree PAT 甲级
    jQuery的基本使用
    案例:移动端返回顶部效果
    移动端轮播图(原生JS写法)
    移动端特效
    本地存储
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6034348.html
Copyright © 2011-2022 走看看