zoukankan      html  css  js  c++  java
  • iOS常用技术-Label自适应

     1 //
     2 //  ViewController.m
     3 //  Label的自适应
     4 //
     5 //  Created by 大欢 on 16/1/19.
     6 //  Copyright © 2016年 bjsxt. All rights reserved.
     7 //
     8 
     9 #import "ViewController.h"
    10 
    11 @interface ViewController ()
    12 
    13 @end
    14 
    15 @implementation ViewController
    16 
    17 - (void)viewDidLoad {
    18     [super viewDidLoad];
    19 
    20 //    [self example1];
    21     
    22     
    23     NSString * string = @"还记得你说家是唯一的城堡随着稻香河流继续奔跑微微笑 小时候的梦我知道不要哭让萤火虫带著你逃跑乡间的歌谣永远的依靠回家吧 回到最初的美好";
    24     
    25     UILabel * label = [[UILabel alloc] init];
    26     label.text = string;
    27     label.numberOfLines = 0;
    28     label.backgroundColor = [UIColor greenColor];
    29     CGSize size = [label sizeThatFits:CGSizeMake(self.view.frame.size.width - 40, MAXFLOAT)];
    30     label.frame = CGRectMake(20, 50, size.width, size.height);
    31     [self.view addSubview:label];
    32     
    33 }
    34 
    35 - (void)example1 {
    36     
    37     NSString * string = @"还记得你说家是唯一的城堡随着稻香河流继续奔跑微微笑 小时候的梦我知道不要哭让萤火虫带著你逃跑乡间的歌谣永远的依靠回家吧 回到最初的美好";
    38     
    39     UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, self.view.frame.size.width - 40, 0)];
    40     label.text = string;
    41     label.numberOfLines = 0;
    42     label.backgroundColor = [UIColor greenColor];
    43     //使用sizeToFit一定要设置宽度
    44     [label sizeToFit];
    45     [self.view addSubview:label];
    46 }
    47 
    48 @end


    /*************************************************************/

  • 相关阅读:
    ssh框架中文保存数据库MySQL乱码
    SSH ERROR com.opensymphony.xwork2.interceptor.ParametersInterceptor
    SSH(六)hibernate持久层模板于事务管理
    SSH(五)spring整合hibernate
    javaweb string
    spring加载配置文件
    order by 与 group by 区别
    PowerDesigner从SqlServer数据库中导入实体模型
    方向
    关于Hibernate 的数据库配置
  • 原文地址:https://www.cnblogs.com/MrWuYindi/p/5146593.html
Copyright © 2011-2022 走看看