- (void)drawRectFor7
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0 UIFont *font = [UIFont boldSystemFontOfSize:_fontSize]; NSDictionary *attributes = nil;
NSDictionary *strokeAttributes = nil;
if (_useLightText)
{
strokeAttributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, _strokeColor, NSStrokeColorAttributeName, @-10.0, NSStrokeWidthAttributeName, nil]; attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, _lightColor, NSForegroundColorAttributeName, nil];
}
else
{
attributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, _normalColor, NSForegroundColorAttributeName, nil];
} // draw text
int i = ;
double unitStartX = 0.0;
for (NSString *str in _strings)
{ CGSize size = [str sizeWithAttributes:attributes];
double startX = _segmentLengthInPixels * i - size.width / 2.0 + kScaleSegmentMargin; ++i; // draw units string position
if (_withUnits && i == _strings.count)
{
startX = unitStartX;
}
else
{
unitStartX = _segmentLengthInPixels * (i - ) + size.width / 2.0 + kScaleSegmentMargin * ;
} if (strokeAttributes != nil)
{
[str drawAtPoint:CGPointMake(startX, ) withAttributes:strokeAttributes];
} [str drawAtPoint:CGPointMake(startX, ) withAttributes:attributes];
} #endif
}
- (void)drawRectFor6
{
// obtain current context
CGContextRef context = UIGraphicsGetCurrentContext(); // save context state first
CGContextSaveGState(context); // set text color in context
if (_useLightText)
{
CGContextSetFillColorWithColor(context, _lightColor.CGColor);
}
else
{
CGContextSetFillColorWithColor(context, _normalColor.CGColor);
} UIFont *font = [UIFont boldSystemFontOfSize:_fontSize]; // draw text
int i = ;
double unitStartX = 0.0;
for (NSString *str in _strings)
{ CGSize size = [str sizeWithFont:font];
double startX = _segmentLengthInPixels * i - size.width / 2.0 + kScaleSegmentMargin; ++i; // draw units string position
if (_withUnits && i == _strings.count)
{
startX = unitStartX;
}
else
{
unitStartX = _segmentLengthInPixels * (i - ) + size.width / 2.0 + kScaleSegmentMargin * ;
} //draw stroke
if (_useLightText)
{
CGContextSaveGState(context);
CGContextSetTextDrawingMode(context, kCGTextStroke);
CGContextSetStrokeColorWithColor(context, _strokeColor.CGColor);
[str drawAtPoint:CGPointMake(startX, ) withFont:font];
CGContextRestoreGState(context);
} [str drawAtPoint:CGPointMake(startX, ) withFont:font]; } // restore context state
CGContextRestoreGState(context);
}

userLightText模式下绘制白底黑边字符串,普通模式下绘制黑色字。

ios7 下使用

- (void)drawAtPoint:(CGPoint)point withAttributes:(NSDictionary *)attrs  进行绘制。

需要定义attributes,对样式进行定义。

ios7 之前使用

- (CGSize)drawAtPoint:(CGPoint)point withFont:(UIFont *)font 绘制。

ios drawRect NSString 绘制的更多相关文章

  1. iOS界面的绘制和渲染

    界面的绘制和渲染 UIView是如何到显示的屏幕上的. 这件事要从RunLoop开始,RunLoop是一个60fps的回调,也就是说每16.7ms绘制一次屏幕,也就是我们需要在这个时间内完成view的 ...

  2. iOS可视化动态绘制连通图

    上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...

  3. iOS的阴影绘制及性能优化

    今天来讲讲iOS开发过程中的阴影绘制及其潜在的绘图性能问题.虽然在开发过程中,我们使用阴影功能的机会不是很多,但是如果用了,有可能引起如卡顿等性能问题,所以,还是有必要来探究一下阴影的绘制过程,及如何 ...

  4. iOS可视化动态绘制连通图(Swift版)

    上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...

  5. ios 绘图,绘制坐标系,画坐标系

    先来看个效果: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...

  6. iOS - drawRect致内存增加

    GPU VS CPU iOS - 软件绘图 自定义"斑马线背景"View,重写drawRect绘制斑马线: ⚠️ 仅仅添加这一个View,内存就比正常增加了3-5M之间. 测试源代 ...

  7. IOS开发 图形绘制,绘制线条,矩形,和垂直和居中绘制文字

    概述 吐槽下IOS下 的图形绘图,代码冗长,不得不自己重新封装方法.整理形成本文. 绘制线 // 绘制直线 + (void)toDrawLineFromX:(CGFloat)x1 Y:(CGFloat ...

  8. IOS Quartz 各种绘制图形用法---实现画图片、写文字、画线、椭圆、矩形、棱形等

    // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affec ...

  9. IOS开发中绘制地图线路

    地图应用经常会涉及到线路的绘制问题,ios下可以使用MKMapView进行地图开发,使用 MKOverlayView进行线路的绘制. 使用MKMapView添加MKMap.framework 和Cor ...

随机推荐

  1. leetCode 26.Remove Duplicates from Sorted Array(删除数组反复点) 解题思路和方法

    Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that e ...

  2. Linux crontab 命令详解(含配置文件路径)

    编辑/etc/crontab 文件配置cron cron 服务每分钟不仅要读一次/var/spool/cron内的所有文件,还需要读一次/etc/crontab,因此我们配置这个文件也能运用cron服 ...

  3. C++之static

    一.静态全局变量和非静态全局变量 1. 隐藏作用 比较非静态全局变量和静态(static)全局变量: 对于多个文件的代码,非静态全局变量和函数都是全局可见的.举例如下: a.c中: #include& ...

  4. 根据goodsId获得相关商品的列表

    List<Goods> goodsList = goodsDetailService.getGoodsListByproductId(productId); for (Goods good ...

  5. java09数组的使用

    /** * 数组:存储相同数据类型的一组数据! * 声明一个数组就是在内存中开辟了一连串的连续空间! * * 数组和String 都是 引用数据类型 * 数组的使用 */ @Test public v ...

  6. ckeditor常用设置

    1.首先下载ckeditor放入自己的项目WebRoot目录下 2.在自己的页面中引入需要的js库 3.在界面中书写多行文本域 必须要有name或者id属性  不然没有效果显示 4.修改ckedito ...

  7. MVC4数据访问EF查询linq语句的时候报错找不到表名问题

    一天做项目的时候遇到这样的问题,MVC4用EF访问数据查询用linq语句的时候报错找不到表名:报错如下图: 研究了几种情况,最后还是没有找到正真的问题所在,不过可能是和路由解析问题有关,暂时还没有进行 ...

  8. Windows Media Player Plus

    Windows Media Player Plus 是一款 Windows Media Player 的插件,提供很多实用功能,Mark 一下.

  9. svg学习笔记

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  10. PHP输出中文乱码的问题(转)

    用echo输出的中文显示成乱码, 其实应该是各种服务器脚本都会遇到这个问题, 根本还是编码问题, 一般来说出于编码兼容考虑大多的页面都将页面字符集定义为utf-8 <meta http-equi ...