- (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. [转] When exactly does the virtual table pointer (in C++) gets set for an object?

    PS: http://stackoverflow.com/questions/7934540/when-exactly-does-the-virtual-table-pointer-in-c-gets ...

  2. 【转】关于Ubuntu的sources.list 的总结

    一.作用 文件/etc/apt/sources.list是一个普通可编辑的文本文件,保存了ubuntu软件更新的源服务器的地址.和sources.list功能一样的是/etc/apt/sources. ...

  3. Bzoj3990 [SDOI2015]排序

    Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 651  Solved: 338 Description 小A有一个1-2^N的排列A[1..2^N], ...

  4. TP框架多表联查

    join方法import("@.ORG.Page");        $Form   =   M('gly');        $where='';        if ($_PO ...

  5. 2008年NOI全国竞赛 假面舞会

    /* 分三种情况 1 有环:找环长的gcd作为max gcd的超过2的最小因子作为min 2 树:所有最长链的和作为max 3为min (最长链≥3) 3 两条相交链:找出所有的这样的两条链的差 同1 ...

  6. H1标签使用的七大注意事项

    H1标签使用的七大注意事项: 1 每个页面都应该有H1标签,H1标签是每个网页不可缺少的要素. 2 使用H1标签的内容应该简洁明了; 3 H1标签要尽量出现在源文件代码的开头的部分,这样可以让访问者和 ...

  7. 腾讯云(centos7)上安装并配置PHP

    1.查看yum上的php $ yum list php Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cach ...

  8. 《Java编程思想》之重点笔记——多态性理解

    Java中除了static方法和final方法(private方法本质上属于final方法,因为不能被子类访问)之外,其它所有的方法都是动态绑定,这意味着通常情况下,我们不必判定是否应该进行动态绑定— ...

  9. asp.net+Sqlserver 通过存储过程读取数据

    Sqlserver代码  创建存储过程如下: /*根据父id获取类别总数*/ IF EXISTS (SELECT name FROM sysobjects WHERE name = N'getsite ...

  10. osg for android (一) 简单几何物体的加载与显示

    1. 首先需要一个OSG for android的环境. (1).NDK 现在Eclipse 对NDK已经相当友好了,已经不需要另外cygwin的参与,具体可以参考 Android NDK开发篇(一) ...