- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想在用户键入时向可编辑的 UITextView
文本添加轮廓或描边。完全像模因:http://t.qkme.me/3oi5rs.jpg
我必须使用 UITextView
因为我需要多行支持。我已经尝试了所有方法并得出结论,我必须使用 CoreText
。我得到了几乎所有的解决方案,但卡在了 textview 中的文本换行的位置。我在 UITextView
的 subview
中的 drawRect
例程正确绘制轮廓文本,直到文本换行。即使用户输入的文本被换行,我绘制的轮廓文本也不会换行。这是我对 drawRect
方法的实现:https://gist.github.com/4498988 .在第 29 行,我使用字符包装:
CTLineBreakMode linebreakmode = kCTLineBreakByCharWrapping;
我已经尝试过 wordwrapping 选项(这也是默认选项)没有用。
我的问题是:如何让我绘制的文本正确换行,使其显示为键入文本的轮廓?
最佳答案
// make your UITextView as a subclass of UITextView
// and override -drawRect: method in your UITextView subclass
- (void)drawRect:(CGRect)rect
{
self.textColor = [UIColor clearColor];
[self setTypingAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.font, NSFontAttributeName, _textBaseColor, NSForegroundColorAttributeName, nil ]]; // _textBaseColor is any color of your choice
CGRect newRect = CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextDrawingMode(context, kCGTextStroke);
// Make the thickness of the outline shadow. and increase the y position of shadow rect by 2.
CGContextSetLineWidth(context, (TEXTOUTLINE_PERCENT/100 * self.font.pointSize)+1); // TEXTOUTLINE_PERCENT can be 25.
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context, kCGLineCapButt);
CGContextSetStrokeColorWithColor(context, [UIColor clearColor].CGColor);
CGRect shadowrect = newRect;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
shadowrect.origin.y += 0.5;
}
else
{
shadowrect.origin.y += 2;
}
[self.text drawInRect:shadowrect withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.font, NSFontAttributeName, SHADOW_COLOR , NSForegroundColorAttributeName, nil]]; // SHADOW_COLOR can be [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.3]
// Make the thickness of the outline border of the text.
CGContextSetLineWidth(context, TEXTOUTLINE_PERCENT/100 * self.font.pointSize); // TEXTOUTLINE_PERCENT can be 25.
CGContextSetStrokeColorWithColor(context, [[UIColor clearColor] CGColor]);
[self.text drawInRect:newRect withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.font, NSFontAttributeName, self.textOutlineColor , NSForegroundColorAttributeName, nil]];
// Draw filled text. This is the actual text.
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
[self.text drawInRect:newRect withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.font, NSFontAttributeName, _textBaseColor, NSForegroundColorAttributeName,_textBaseColor, NSStrokeColorAttributeName, nil]];
[super drawRect:rect];
}
关于ios - 向 UITextView 添加轮廓/描边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14250148/
目标 我正在尝试创建一个 SVG 图标以添加到图标字体文件中。 进展 我已经创建了一个 SVG 图标,它以内嵌的形式完美呈现并作为 img 问题 当我上传它以添加到我的图标字体时,同时使用 Icomo
我有一个带边框的动态宽度/高度 div。里面是一个绝对定位的按钮,位于底部的中心,与父 div 的边框重叠。我想让它看起来像边框在重叠按钮之前停止几个像素。一项要求是保持一切动态,例如,如果按钮的宽度
Unity UGUI的Outline(描边)组件的介绍及使用 1. 什么是Outline(描边)组件? Outline(描边)组件是Unity UGUI中的一种特效组件,用于给UI元素添
我需要动态创建这样的大纲: 不是针对一个 CCSprite,而是针对一个 CCNode 中的多个动画 CCSprite。我在想: 将 CCNode 的内容复制到纹理(如 AS3 中的 canvasBi
我正在寻找一种使用 HTML Canvas 对笔划进行动画绘制的方法。 是否有任何预定义的内容可以让您执行此操作? 最佳答案 我不知道任何预定义的解决方案。也许在图书馆里。像raphael 但是如果您
我正在尝试添加一些动画来更改 Canvas 弧的 endAngle,如下所示,但它不起作用。我怎样才能做到这一点? var steps =30; var canvas = document.getEl
我有一个具有以下背景的按钮: 我需要在代码中
我有子类 NSImageView,我想用圆角画一个边框。它可以工作,但我还需要剪掉图像的角。 请看我的截图: 我创建了这段代码来绘制边框/角。 - (void)drawRect:(NSRect)dir
查看positionly.com使用的图表:https://www.dropbox.com/s/kz9ksagctf7zpaa/Screenshot%202015-12-18%2010.31.03.p
我刚刚开始使用 Apache PDFBox,对于应用于文本和线条时描边、非描边和填充的含义,我完全感到困惑。 请有人向我指出一个引用/指南,其中解释了这些术语的含义(对于初学者)以及它们之间的区别。
我正在使用 svg/d3 创建一个由“矩形”元素组成的图表。 为每个矩形(仅在矩形顶部)添加部分边框/描边的最佳方法是什么? 谢谢 最佳答案 我认为 SVG 不支持仅对矩形或路径的部分进行描边 - 描
我正在学习 Canvas ,我的目标是徒手绘画。每个在线示例都说我应该在我的 onmousemove 中调用 stroke()。如果我的颜色 strokeStyle 具有 100% 的不透明度,这将按
我想在用户键入时向可编辑的 UITextView 文本添加轮廓或描边。完全像模因:http://t.qkme.me/3oi5rs.jpg 我必须使用 UITextView 因为我需要多行支持。我已经尝
如何在 material-ui 图标周围添加颜色轮廓? 有这个 看起来更像这样? 我尝试过中风和 webkit-stroke,但没有任何运气。它在整个隐形盒子周围放置了一个边框。 最佳答案 在 Rea
我在 drawRect 中绘制了一个形状,它存储在 CGMutablePathRef (shapeMutablePath) 中。每次调用 drawRect 时,形状都会被拉伸(stretch)以适应屏
我已经使用以下代码向我的 map 添加了一个叠加层: func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!)
我有一个 CAShapeLayer,它有一个不透明的描边和一个透明的填充。然后我想调用 myContext.drawRadialGradient,但是将这个径向渐变剪辑到我的形状层的笔划。目前,我正在
我已将我的 SVG 图像设置为 div 的背景。现在我想每隔 x 秒用 jQuery 更改特定路径的笔画。我看过一个示例 ( click me ),其中基本上完成了此操作。 到目前为止,这是我的 jQ
我正在努力寻找一种快速绘制(和填充)贝塞尔曲线路径的方法。这是我认为行得通但行不通的方法。 var myBezier = UIBezierPath() myBezier.moveToPoint(CGP
我尝试了很多很多方法在图像周围画一个黑色轮廓。 这是我想要的结果示例: 有人可以告诉我我应该怎么做吗?或者给我举个例子? 编辑:我卡在这里:有人可以帮我完成它吗?我所做的是在带有阴影的白色下制作另一个
我是一名优秀的程序员,十分优秀!