思路:

  写一个 UILbel的子类;在子类里面重新布置UILbel的字体间距;

如代码 .h

#import <UIKit/UIKit.h>

@interface AdjustableUILable : UILabel
{
CGFloat characterSpacing;
} @property CGFloat characterSpacing;
@end

 代码 .m

#import "AdjustableUILable.h"

@implementation AdjustableUILable
@synthesize characterSpacing; - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) { }
return self;
} - (void)drawTextInRect:(CGRect)rect
{
if (characterSpacing)
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat size = self.font.pointSize; CGContextSelectFont (context, [self.font.fontName UTF8String], size, kCGEncodingMacRoman);
CGContextSetCharacterSpacing (context, characterSpacing);
CGContextSetTextDrawingMode (context, kCGTextFill); // Rotate text to not be upside down
CGAffineTransform xform = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0);
CGContextSetTextMatrix(context, xform);
const char *cStr = [self.text UTF8String];
CGContextShowTextAtPoint (context, rect.origin.x, rect.origin.y + size, cStr, strlen(cStr));
}
else
{
// no character spacing provided so do normal drawing
[super drawTextInRect:rect];
}
} @end

  如何使用:

    HistoryToday *yearDates = [HistoryToday today];
AdjustableUILable *yearLabel = [[AdjustableUILable alloc]initWithFrame:CGRectMake(18, 6, 240, 30)];
yearLabel.text = yearDates.year;
yearLabel.characterSpacing = 14;
[self.view addSubview:yearLabel];

  

UILabel字体间距调整的更多相关文章

  1. iOS 学习 - 23 加载本地 txt 文件, NSMutableParagraphStyle 段落格式,缩放动画,字体间距

    思路: 1.new 一个 Empty 后缀为 .txt 文件,内容随笔拷贝一段 2.用 NSString 接收本地文件,再用一个标题拼接字符串 3.创建一个 NSMutableParagraphSty ...

  2. css 字间距、CSS字体间距、css 字符间距设置

    1.text-indent设置抬头距离css缩进 2.letter-spacing来设置字与字间距_字符间距离,字体间距css样式

  3. Eclipse设置:背景与字体大小和xml文件中字体大小调整

    Eclipse中代码编辑背景颜色修改:代码编辑界面默认颜色为白色.对于长期使用电脑编程的人来说,白色很刺激我们的眼睛,所以改变workspace的背景色,可以使眼睛舒服一些.设置方法如下:1.打开wi ...

  4. CSS定义字体间距 字体行与行间距

    CSS定义字体行间距 line-height:xxpx; CSS定义字体间距 下面我们讲述一下CSS的文本属性,还是先来看一下文本属性的详细列表: 属性     属性含义     属性值 Word-s ...

  5. Pycharm 字体大小调整

    Pycharm 字体大小调整 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/awyyauqpmy/article/details/79334496P ...

  6. Eclipse中设置背景颜色与字体大小和xml文件中字体大小调整

    Eclipse中代码编辑背景颜色修改: 代码编辑界面默认颜色为白色.对于长期使用电脑编程的人来说,白色很刺激我们的眼睛,所以改变workspace的背景色,可以使眼睛舒服一些.设置方法如下: 1.打开 ...

  7. css中字间距调整(转)

    css中字间距调整 (2014-01-02 13:51:07) 标签: 汉字 英文 间距 letter-spacing word-spacing 杂谈 分类: 网页制作 汉字间字间距设置:letter ...

  8. Eclipse设置:背景与字体大小、xml文件中字体大小调整和自动提示 SVN插件安装

    Eclipse中代码编辑背景颜色修改: 代码编辑界面默认颜色为白色.对于长期使用电脑编程的人来说,白色很刺激我们的眼睛,所以改变workspace的背景色,可以使眼睛舒服一些.设置方法如下: 1.打开 ...

  9. MyEclipse背景与字体大小和xml文件中字体大小调整

    1.打开window / Preference,弹出Preference面板 2.展开General标签,选中Editors选项,展开. 3.选中 Text Editors,右边出现TestEdito ...

随机推荐

  1. lua协程----ngx-lua线程学习笔记

    --[[ - @desc lua数据输出 - @param string 字符串 - return string --]] function dump(v) if not __dump then fu ...

  2. VC/MFC分割字符串(SplitString)返回CStringArray

    引自:http://bbs.csdn.net/topics/60321228 原版: CStringArray* SplitString(CString string, char pattern) { ...

  3. win7 64位安装pywin32

    先安装pywin32-218.win-amd64-py3.4.exe文件: 安装完成后,用CMD管理员模式进入\Python34\Scripts\目录 输入pywin32_postinstall.py ...

  4. Python知识(6)--numpy做矩阵运算

    矩阵运算 论numpy中matrix 和 array的区别:http://blog.csdn.net/vincentlipan/article/details/20717163 matrix 和 ar ...

  5. php在linux后台执行

    <?php ignore_user_abort();//后台运行 ini_set('default_socket_timeout', -1);//socket不超时 set_time_limit ...

  6. ubuntu 自动获取ip

    $sudo dhclient -r $sudo dhclient $sudo dhclient eth0

  7. MAIN/autoslb.py · 林語/autoslb - 码云 - 开源中国

    MAIN/autoslb.py · 林語/autoslb - 码云 - 开源中国 CloudXNS

  8. mysql官网文档调试MYSQL资料 5.7

    http://dev.mysql.com/doc/refman/5.7/en/debugging-server.html

  9. C# 标签(条码)的打印与设计(二)

    上一篇说到条码的打印,主要是通过读取模板定义文件(XML文件),然后结合从数据库中读取的动态数据结合而产生条码.下面主要说一下如何设计这个条码模板.设计过程也很简单,只需要简单的拖拉即可.然后点击小箭 ...

  10. IoC Containers with Xamarin

    When writing cross platform apps with Xamarin, our goal is share as close to 100% of our code across ...