0118——UILabel和导入字体

UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 100)];

1.设置文字颜色

  label.textColor = [UIColor orangeColor];
label2.textColor = [UIColor purpleColor];

2.设置背景颜色

  label.backgroundColor = [UIColor clearColor];

  lable.textColor = [UIColor colorWithRed:222/255.0 green:59/255.0 blue:17/255.0 alpha:1];

3.设置文字位置

  label.textAlignment = UITextAlignmentLeft;

4.设置label的行数  0表示多行,自适应

  label.numberOfLines = 2;

5.设置阴影

  label.shadowColor = [UIColor redColor];

  label.shadowOffset = CGSizeMake(1.0,1.0);

6.设置文字过长时的显示格式

  label.lineBreakMode = UILineBreakModeMiddleTruncation;//截去中间

  enum {

    UILineBreakModeWordWrap = 0,

    UILineBreakModeCharacterWrap,

    UILineBreakModeClip,//截去多余部分

    UILineBreakModeHeadTruncation,//截去头部

    UILineBreakModeTailTruncation,//截去尾部

    UILineBreakModeMiddleTruncation,//截去中间

  } UILineBreakMode;

7.导入字体包设置自己的字体

在网上下载好字体文件,拖拽的到工程中,选好target

在plist中加入一行,写入字体文件打开后的名字

lable.font = [UIFont fontWithName:@"DFGirlW3-B5" size:20];

8.计算字符串的长度

  a.确定一个大的容器,width或者height 一定,另一个可变,变化的变量一定要大

  b.确定计算font

  c.boundingRectWithSize

    NSString * str = @"The NSString class declares the programmatic interface for an object that manages immutable strings.";

  UIFont * font = [UIFont fontWithName:@"DFGirlW3-B5" size:20];

  NSDictionary * attrDic = @{NSFontAttributeName:font};

  CGSize bigsize = CGSizeMake(300, 3000);

  CGSize realsize = [str boundingRectWithSize:bigsize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrDic context:nil].size;

  UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, realsize.width, realsize.height)];

  label.text = str;

  label.backgroundColor =[UIColor blackColor];

  label.font = [UIFont fontWithName:@"DFGirlW3-B5" size:20];

  label.textColor = [UIColor colorWithRed:222/255.0 green:59/255.0 blue:17/255.0 alpha:1];

  label.textAlignment =NSTextAlignmentLeft;

  label.numberOfLines = 0;

  label.lineBreakMode = NSLineBreakByWordWrapping;

时间: 2024-08-04 01:49:02

0118——UILabel和导入字体的相关文章

UILabel + 导入字体

UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 100)]; 1.设置文字颜色 label.textColor = [UIColor orangeColor]; label2.textColor = [UIColor purpleColor]; 2.设置背景颜色 label.backgroundColor = [UIColor clearColor]; lable.textColor = [UICo

iOS运用runtime全局修改UILabel的默认字体

iOS运用runtime全局修改UILabel的默认字体 一.需求背景介绍 在项目比较成熟的基础上,遇到了这样一个需求,应用中需要引入新的字体,需要更换所有Label的默认字体,但是同时,对于一些特殊设置了字体的label又不需要更换.乍看起来,这个问题确实十分棘手,首先项目比较大,一个一个设置所有使用到的label的font工作量是巨大的,并且在许多动态展示的界面中,可能会漏掉一些label,产生bug.其次,项目中的label来源并不唯一,有用代码创建的,有xib和storyBoard中的,

运用Runtime全局修改UILabel的默认字体

今天同事项目遇到一个问题,要修改所有UILabel的字体,我查了以下资料,推荐使用runtime机制替换掉UILabel的初始化方法,对label的字体进行默认设置.主要替换以下三个方法initWithFrame.init和xib用到的awakeFromNib,创建UILabel的类别代码如下: .h #import <UIKit/UIKit.h> @interface UILabel (LabelDefaultFont) @end .m #import "UILabel+Label

iOS:UILabel设置不同字体颜色

NSString *str = @"0123456789";//label内容 NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:str]; //根据下标索引设置字体颜色 [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];

CSS3导入字体后用另外一种索引去加载字体里面的字符的问题。

上面的图为正常引用字体里面对应的字符标示! 在页面展示只需要一个class 就能引用出来. 但是我发现一些国外的网站模板里面引用可另外一种索引方式 介绍如下: 第一步引用字体 ? 第二步: ? 加载class字体 在页面上 引入css 下面就是页面展示的参数,拿其中一个举例子: 展示效果" 他在span标签引用这个icon 但是没有指定 我们正常模式下面的例如 icon-car 这样而是统一了icon   用了一个html的字符编码= ? f104是这个字符的Unicode编码 除了常见的预先命

如何设置UILabel中的字体的间距

1 cell.teacherDescriptionLabel.text = content; 2 cell.teacherDescriptionLabel.textAlignment = NSTextAlignmentJustified; 3 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:content]; 4 NSMutableParagraphSt

HTML [email&#160;protected] 导入字体

@font-face {     font-family: 'emotion';     src=\'#\'" /* IE9*/     src=\'#\'" /* IE6-IE8 */          url('emotion.woff') format('woff'), /* chrome.firefox */          url('emotion.ttf')  format('truetype'), /* chrome.firefox.opera.Safari, Andr

UILabel字体加粗等属性和特效

/* Accessing the Text Attributes text  property font  property textColor  property textAlignment  property lineBreakMode  property enabled  property Sizing the Label’s Text adjustsFontSizeToFitWidth  property baselineAdjustment  property minimumFontS

iOS字体包导入过程

iOS导入字体包: 1.将所用到的字体包导入xcode 2.在info.plist里新建一个Fonts provided by application(array),将字体名称填入 3.在工程build phases->copy bundle resources中查看文件是否添加成功 4.自定义方法,将字体名称一一对应放入 注意:我们在使用该文件时,要用其全名,不是文件名 如下图所示:文件名是ProximaNova-RegularItalic 但是,其全名是:ProximaNova-Regula