ios drawRect NSString 绘制
- (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 绘制的更多相关文章
- iOS界面的绘制和渲染
界面的绘制和渲染 UIView是如何到显示的屏幕上的. 这件事要从RunLoop开始,RunLoop是一个60fps的回调,也就是说每16.7ms绘制一次屏幕,也就是我们需要在这个时间内完成view的 ...
- iOS可视化动态绘制连通图
上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...
- iOS的阴影绘制及性能优化
今天来讲讲iOS开发过程中的阴影绘制及其潜在的绘图性能问题.虽然在开发过程中,我们使用阴影功能的机会不是很多,但是如果用了,有可能引起如卡顿等性能问题,所以,还是有必要来探究一下阴影的绘制过程,及如何 ...
- iOS可视化动态绘制连通图(Swift版)
上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...
- ios 绘图,绘制坐标系,画坐标系
先来看个效果: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...
- iOS - drawRect致内存增加
GPU VS CPU iOS - 软件绘图 自定义"斑马线背景"View,重写drawRect绘制斑马线: ⚠️ 仅仅添加这一个View,内存就比正常增加了3-5M之间. 测试源代 ...
- IOS开发 图形绘制,绘制线条,矩形,和垂直和居中绘制文字
概述 吐槽下IOS下 的图形绘图,代码冗长,不得不自己重新封装方法.整理形成本文. 绘制线 // 绘制直线 + (void)toDrawLineFromX:(CGFloat)x1 Y:(CGFloat ...
- IOS Quartz 各种绘制图形用法---实现画图片、写文字、画线、椭圆、矩形、棱形等
// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affec ...
- IOS开发中绘制地图线路
地图应用经常会涉及到线路的绘制问题,ios下可以使用MKMapView进行地图开发,使用 MKOverlayView进行线路的绘制. 使用MKMapView添加MKMap.framework 和Cor ...
随机推荐
- css01入门小例子
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- RadioGroup单选按钮排版
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- 腾讯云升级到PHP7
1.删除之前安装的PHP yum remove php* php-common 2.安装yum源 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel ...
- Ecstore中Mootools和Jquery如何同时存在,解决冲突?
- DHCP租约时间工作原理
问题: 很多用户在使用路由器的DHCP服务器过程中都有一个疑问,DHCP有个设置项目是设置DHCP地址的租约时间,如果设置的比较短,是否会出现租约时间到了以后会重新去获取ip地址,造成用户断网? ...
- Python正则表达式一
推荐 http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html#!comments 这篇博客超好,建议收藏. 不过对于正则表达式小白,他没 ...
- C++重载操作符
重载的函数操作符,对对象使用起来就像对象是一个函数一样 class A{public:A(int n);int operator()(int n); //需要一个参数,返回int类型void out ...
- Ubuntu下MySQL配置为外网访问
Ububtu安装MySQL后默认外网无法连接,但是很多时候我们想要在外网访问方便管理.在这里,简单叙述一下自己在配置过程中的操作,步骤如下: 以root身份登入mysql mysql -u root ...
- FileZilla 无法保存密码
当保存密码时遇到这个问题时: 解决办法: 一.找到FileZilla的设置: 二.点击"界面",取消勾选"不要保存密码",点击"确定"按钮, ...
- Android Framework------之PowerManagerService的功能
自从接触Android系统已经一年多了,这段时间内对于Android系统的Framework层的各个模块都有过接触,有时也做过分析,但是一直没能形成一个总结性的东西.这次下定决心,好好整理整理对于An ...