- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将实现用于将白色数字添加到正在绘制到 ios 应用程序上的 UIImage
的箭头上的模块。执行时,显示数字上只设置了黑色。我已经添加了
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), [UIColor whiteColor].CGColor);
但无济于事。你能告诉我这是更好的方法吗?
下面是我的作品
-(UIImage*) drawText:(NSString*) text
inImage:(UIImage*) image
atPoint:(CGPoint) point
{
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];
CGRect rect = CGRectMake(point.x, point.y, image.size.width, image.size.height);
[[UIColor whiteColor] set];
UIFont *font = [UIFont boldSystemFontOfSize:24];
if([text respondsToSelector:@selector(drawInRect:withAttributes:)])
{
//IOS 7
NSDictionary *att = @{NSFontAttributeName:font};
[text drawInRect:rect withAttributes:att];
}
else
{
[text drawInRect:CGRectIntegral(rect) withFont:font];
}
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), [UIColor whiteColor].CGColor);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
最佳答案
根据您想回到多远的时间,选择这 3 种解决方案中的任何一种。6+ 和 7+ 版本使用 NSForegroundColorAttributeName
来选择颜色。这些是首选方法。
iOS 7+
// (add the color to the attribute)
NSDictionary *att = @{NSFontAttributeName :font,
NSForegroundColorAttributeName:[UIColor whiteColor]};
[@"test" drawInRect:rect withAttributes:att];
iOS 6+(也适用于 iOS 7)
// (add the color to the attribute, using NSAttributedString)
NSDictionary *att = @{NSFontAttributeName :font,
NSForegroundColorAttributeName:[UIColor whiteColor]};
NSAttributedString * text = [[NSAttributedString alloc] initWithString:@"test"
attributes:att];
[text drawInRect:rect];
iOS 5(不适用于 iOS 7)
// No attributes involved
[[UIColor whiteColor] set];
[@"test" drawInRect:CGRectIntegral(rect) withFont:font];
关于ios - 更改 UIImage 或 UIGraphics 的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24665806/
这段代码似乎有内存泄漏,但我找不到它。我究竟做错了什么?具体来说,第 1 行和第 2 行会增加应用程序的内存使用量,只有第一行的内存会在上下文结束时消失。 UIGraphicsBeginImageCo
在 MonoTouch 上调用 UIGraphics.BeginPDFContext 时,我无法提供 PDF 文档信息。我尝试过使用采用 CGPDFInfo 的重载和采用 NSDictionary 的
如何创建带边框的圆形图像(UIGraphics)? 附言我需要画一幅画。 viewDidLoad 中的代码: NSURL *url2 = [NSURL URLWithString:@"http://i
我正在尝试用一些额外的信息覆盖图像:一些文本和矩形。现在我一直在画矩形。他们只是不会出现。我究竟做错了什么?正在绘制图像本身,因此图形上下文必须正常。 - (void)drawTag:(NSStrin
我正在尝试使用 UIGraphics 调整图像的大小。图片是用相机拍的,我用的是这段代码: CGSize origImageSize = photograph.size; //this sa
我想为 AppleWatch 开发一种进度条动画。 我决定用 来做这一切UIGraphicContext . 由于我是一个完整的初学者,我真的不明白如何将某种“globalCompositeOpera
构建一个功能,类似于 Snapchat 的贴纸。制作照片,添加贴纸(表情符号),发布图像。我当前的 View 层次结构是: 主视图 查看用户照片 ui 元素 View (“取消/添加贴纸/帖子”)+
我正在尝试制作一个简单的应用程序,将相机叠加层与在 UIImagePicker 中拍摄的照片相结合。在这个例子中,我想将熊耳朵的叠加 View 与照片结合起来。 - (IBAction)pushTak
因此 pdf 的创建效果很好,然后我有一些要添加到此 pdf 的贝塞尔曲线路径,我不确定如何添加它并设置它的位置 文件内部: //pdf UIGraphicsBeginPDFContextT
我有一个幻灯片放映,允许用户使用简单的绘图工具对幻灯片进行注释。只允许您用手指在屏幕上绘图,然后“保存”。保存功能使用 UIImagePNGRepresentation 并且效果很好。我需要解决的是如
我有一个 UIViewController,其中包含 2 个 subview (从 UIView 派生的类),它们使用 UIGraphics.GetCurrentContext 进行自定义绘图。该绘图
我将实现用于将白色数字添加到正在绘制到 ios 应用程序上的 UIImage 的箭头上的模块。执行时,显示数字上只设置了黑色。我已经添加了 CGContextSetFillColorWithColor
不久前,我找到了一些代码,用于根据状态更改 UIButton 的背景颜色。代码如下所示: extension UIButton { func setBackgroundColor(_ colo
我有一个应用程序已经在 iOS 6 上进行了广泛测试并且运行良好,而在 iOS 7 上它几乎总是崩溃(但不是 100% 次)并出现 Thread 1: EXC_BAD_ACCESS 错误主要的,没有太
我正在使用 UIGraphicsBeginPDFContextToData 绘制 PDF,它工作正常,只是文档始终为无标题。使用 UIGraphics 时是否可以设置标题元数据,或者我是否需要使用 C
我正在使用带有 contentMode:UIViewContentModeScaleAspectFill 的 UIImageView,其中包含未完全填充 UIImageView 的图像。 例如 UII
我正在使用 Rubymotion 而不是 Objective-C/Xcode 编写应用程序。 我发现很多 Objective-C 的编写方式更像是过程代码,而不是面向对象,并且我试图让我的代码比大多数
我试图让我的头脑围绕 Objective-C 并且快速挣扎。我猜我在这里问的问题很简单,但我似乎无法在 StackOverflow、Mac 开发者库或互联网上的任何地方找到我的问题的答案。 我正在尝试
我是一名优秀的程序员,十分优秀!