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 ...
随机推荐
- Install the OpenStack command-line
Install the OpenStack command-line Install the prerequisite software python 2.7 or later note: Curre ...
- bootstrap字体图标
bootstrap字体图标 http://v3.bootcss.com/components/ <!DOCTYPE HTML> <html> <head> < ...
- crontab 配置
* * * * * (cd /opt/bd/www/crm/scripts/zb_insure; /opt/tuniu/php/bin/php /opt/bd/www/crm/scripts/zb_i ...
- 获取EnterpriseLibrary企业库配置文件中ConnectionStrings(原创)
在使用企业类库时想取出单独企业配置文件中的连接字符串遍历,并放到自己的数据库处理类中,在查找了很久的资料后都没有找到,于是自己探索着写了一个,共享给大家以做参考: ConfigurationSourc ...
- C#获取显示器宽度高度,桌面宽度高度等
1.C#获取显示器宽度高度,桌面宽度高度等 //获取当前显示器的宽度和高度 int width = Screen.PrimaryScreen.Bounds.Width; int height = Sc ...
- java获取字符串格式日期向前或向后n天的日期
private void setTilteMessage(){ BaseDao dao = new BaseDao(); String titleData = da ...
- Android开发手记(13) 几种Alertdialog的使用
本文主要讨论七种形式的AlertDialog,及其编写方法. 1.退出 在用户退出的时候提示用户是否退出,含有“确定”和“退出”两个按键. btnExit.setOnClickListener(new ...
- 怎样取得数组对象和arralist 的长度
数组用length属性 ArrayList用size()方法
- Nagios配置—添加linux主机监控
nagios安装请参看:Nginx平台安装Nagios监控服务 下面是我添加linux监控机的过程,如有错误或者不当的地方请指出: 测试环境: 监控主机:nagios+nagios插件+nrpe+网站 ...
- ORACLE搭建Stream过程中报错【error收集】
错误一:在配置完源库和目标数据库后,创建复制管理员.连接上复制管理员后,在源库执行MAINTAIN_TABLE过程: declare v_tables DBMS_UTILITY.UNCL_ARRAY; ...