UI控件之UILable

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

  //如何计算文本在一定情况下的具体高度和宽度


    //size:计算的参考尺寸,必须高度或者宽度确定


    NSString *text = @"The UIViewController class provides the infrastructure for managing the views of your iOS apps";


    //指定计算文本宽高时,所用的字体和字号


    NSDictionary *attrDic = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};


    CGSize realSize = [text boundingRectWithSize:CGSizeMake(self.view.bounds.size.width - 100, 3000) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrDic context:nil].size;


 


  //创建 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, self.view.bounds.size.width - 100, realSize.height)]; //设置显示的内容 label.text = text; //设置字体颜色 label.textColor = [UIColor orangeColor]; //设置字体和字号 label.font = [UIFont systemFontOfSize:20]; //设置多行显示 0表示自动换行 label.numberOfLines = 0; //设置换行方式,Word表示按单词换行,char按字符换行 label.lineBreakMode = NSLineBreakByWordWrapping; //设置对齐方式 label.textAlignment = NSTextAlignmentLeft; //添加到界面上 [self.view addSubview:label]; //设置阴影 UIView的方法 label.layer.shadowColor = [UIColor blueColor].CGColor;
  //偏移值 label.layer.shadowOffset
= CGSizeMake(5, 5); label.layer.shadowRadius = 5; label.layer.shadowOpacity = 1; }

注意:具体的可在Main.storyboard中拖动UILabel控件实现

posted @ 2018-08-05 21:06  健泽  阅读(372)  评论(0编辑  收藏  举报