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 ...
随机推荐
- 表达式求值 (栈) 用C++实现
#include <cstdio> #include <cstdlib> #include <cmath> #include <stack> #incl ...
- 零基础学习云计算及大数据DBA集群架构师【Linux Bash Shell编程及系统自动化2015年1月21日周四】
lvy老师教项目课程,以及代课了shell部分课程,大家都觉得这位老师不行,上课时做的操作很多都是错误的,觉得她基础不好.而且,她不能解释原因,学生问为什么,她不知道.崩溃啊.向xx培训机构反应后,说 ...
- JspSmart文件上传与下载
JspSmart 文件上传包,放在WEB-INF/lib下 uploadForm.jsp <%@ page language="java" import="java ...
- AJAX校验用户名是否存在,焦点离开用户名、点击 【 检 查用户名 】的校验。分别用 XMLHttp 和 JQueryAJAX实现。
XMLHttp方法: $("#name").blur(function () { var xmlhttp = new ActiveXObject("Microsoft. ...
- XML and JSON 验证
function ChkJson(strJson) { //判断Json格式是否正确 if (strJson == null || strJson == "") return tr ...
- MySQL数据库my.cnf配置文件注释详解
我们知道,在MySQL数据库安装完成后,要对my.cnf配置文件进行适当的修改才能充分利用MySQL数据库的功能.但是对于初学者来说,修改my.cnf配置文件似乎是一个比较难的过程.为了解决这个问题, ...
- mssql定时执行作业。
---2000 企业管理器 --管理 --SQL Server代理 --右键作业 --新建作业 --"常规"项中输入作业名称 --"步骤"项 --新建 --&q ...
- libthrift0.9.0解析(二)之TSimpleServer
TSimpleServer简单实现Tserver,代码如下. /** * Simple singlethreaded server for testing. * */ public class TSi ...
- JS实现Tab切换
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JAVA-3-水仙花
public static void main(String[] args) { // TODO 自动生成的方法存根 int i = 100; while (i < 1000) { int a, ...