带白色文本和放大镜放大倍率 iPhone 上的清晰背景

发布于 2024-07-30 14:47:46 字数 195 浏览 3 评论 0原文

你们对我的最后一个问题帮助很大,我想我可以再给你们一个机会。 我编写了一个应用程序,其主题使用深蓝色玻璃背景和白色/灰色文本和标签。 我的应用程序中的文本字段具有清晰的彩色背景和白色文本,所有内容都显示得很好。 我唯一担心的是,当您按住文本框中的触摸以获取放大镜时,白色文本当然会显示在白色背景上......您无法阅读。 有人对如何在这里实现可用的放大镜有任何想法吗?

You guys helped so much with my last question, I figured I'd give you a shot at another. I have written an app with a theme that uses a dark blue glassy background and white / gray text and labels. The textfields in my app have clearcolor backgrounds and white texts and everything shows up very well. My only concern is that when you hold down a touch in a text box to get the magnification loupe, of course the white text shows up on a white background... which you can not read. Anybody got any ideas on how to implement a usable loupe here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乄_柒ぐ汐 2024-08-06 14:47:46

不幸的是,我知道如何更改放大镜背景的唯一“公共”方法是通过设置 textField.backgroundColor

我假设由于您将背景设置为clearColor,放大镜默认为白色背景,所以唯一的方法是设置您的背景颜色不清楚。

我还假设,既然您确实提到您将背景设置得很清晰,那么不清晰就不是一个选择。 因此,我可以想到两种解决此问题的方法:

  1. 假设放大倍数通过调用backgroundColor实现(而不是其他一些晦涩的私有API方法)来获取其背景颜色:覆盖backgroundColor方法并返回一个纯色。
  2. 创建自己的放大镜(可能不可行)

Unfortunately, the only "public" way I know how to change the loupe background is by setting textField.backgroundColor

I assume that since you're setting your backgrounds as clearColor, the magnifier defaults to white background, so the only way is to set your backgroundColor as something not clear.

I'm also assuming that since you did mention that you set your backgrounds a clear, that having it not be clear is not an option. So two ways I can think up in my mind about how to get around this is:

  1. Assuming that the magnification lopue gets its background color by calling the backgroundColor implementation (and not some other obscure private API method): override the backgroundColor method and return a solid color.
  2. Create your own loupe (probably not feasible)
枫以 2024-08-06 14:47:46

我想出了一个简单的解决方法,达到了预期的效果。 我也经历了制作自己的放大镜的完整过程,但是由于有关于制作自己的放大镜的明确文档(请参阅kiyoshi的答案),并且另一种方法非常简单,我决定在这里记录它。 它基本上只是伪造清晰的背景,以便白色文本显示在放大镜中。 我用于视图的背景看起来像深蓝色背景上的蓝色烟雾:

alt text http://img231.imageshack.us/img231/9835/beforestatex.jpg

我截取了模拟器的屏幕截图,其中文本字段可见且背景为黑色,因此它会显示得更好:

alt text http://img193.imageshack.us/img193/9023/blackfieldx.jpg

然后我就这么做了屏幕截图并在 Photoshop 中使其半透明,并覆盖我的原始背景图像以准确找到文本字段出现在背景上的位置:

alt text http://img266.imageshack.us/img266/9493/transparencyfullscreenx.jpg

然后我将用作文本字段背景的确切像素复制到新的 PNG 中,然后保存并将其设置为背景图片:

alt text http://img41.imageshack .us/img41/3450/textboxback.png

forwardToField.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"textboxback.png"]];

请记住,图像将作为放大镜内的图案重复...因此,如果您不想看到边缘,只需确保文本字段大于放大镜的高度和宽度即可。

之前:

替代文本http://img196.imageshack.us/img196/2672/beforex。 jpg

之后:

替代文本 http://img23.imageshack.us/img23 /2182/afterxd.jpg

我希望这对那里的人有帮助!

I figured out a simple work around that achieved the desired effect. I also went through the full process of making my own loupe but since there is clear documentation on making your own loupe (see kiyoshi's answer), and this other method is ridiculously simple, I decided to document it here. It is basically just faking the clear background so that the white text shows up in the loupe. The background I am using for the view looks like blue smoke on a darker blue background:

alt text http://img231.imageshack.us/img231/9835/beforestatex.jpg

I took a screenshot of the simulator with the textfield visible and a black background so it would show up better:

alt text http://img193.imageshack.us/img193/9023/blackfieldx.jpg

Then I took that screenshot and made it semi transparent in photoshop, and overlayed my original background image to find exactly where the textfield appeared on the background:

alt text http://img266.imageshack.us/img266/9493/transparencyfullscreenx.jpg

Then I copied the exact pixels that would be used as the background of the textfield into a new PNG and saved that and set it as the the background image:

alt text http://img41.imageshack.us/img41/3450/textboxback.png

forwardToField.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"textboxback.png"]];

Keep in mind that the image will be repeated as a pattern within the loupe... so if you don't want to see the edges, simply make sure your textfield is larger than the loupe height and width.

Before:

alt text http://img196.imageshack.us/img196/2672/beforex.jpg

After:

alt text http://img23.imageshack.us/img23/2182/afterxd.jpg

I hope this helps somebody out there!

古镇旧梦 2024-08-06 14:47:46

实际上创建自己的循环是相当可行的。 还没有尝试过更换苹果,所以不知道他们对此有何感想。

基本思想是覆盖触摸,使用计时器来查看用户触摸屏幕的时间。 放大镜只是一个 UIView,它抓取其后面的视图作为图像并将其放大。

查看 Craftymind 的这篇文章 此处

这篇文章让您缓存整个图像,这对于渲染放大镜来说肯定更快,但是如果您有不断变化的内容(即文本字段),我已经能够渲染实时循环图像,不会对性能造成太大影响。

Actually its pretty feasible to create your own loop. Haven't tried subitting to apple yet so don't know how they feel about it.

Basic idea is override touches, use a timer to see how long the user has been touching the screen. The loupe is just a UIView that grabs as an image the view behind it and magnifies it.

Check out this article from Craftymind here

The article has you cache the entire image behind which is definitely faster, for rendering the loupe, but if you have stuff (i.e. textFields) that are constantly changing I've been able to render the loope image real-time without too much of a performance hit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文