首页 > 其他 > 详细

UI控件之UILable

时间:2018-08-04 21:21:34      阅读:117      评论:0      收藏:0      [点我收藏+]
#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控件实现

UI控件之UILable

原文:https://www.cnblogs.com/jianze/p/9419919.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!