Objective-c:查看背景图案
视图中是否可以有一个可以重复 x 或 y 或两者的模式(例如网格)?有点像 css:
background-image: url(pattern.png); 背景重复:重复; //或者重复-x,重复-y,不重复;
Is it possible to have a pattern (say a grid) in a view that can be repeated x or y or both? Kind of like css:
background-image: url(pattern.png);
background-repeat: repeat; //or repeat-x, repeat-y, no repeat;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下代码将平铺背景图像:
The following code will tile a background image:
是的。您可以将图像图案加载为颜色 (
[NSColor withPatternImage:[NSImage imageNamed:@"pattern"]]
),然后像常规颜色一样绘制它:此代码将重复该图案整个视图,但您可以简单地进行 x 重复或 y 重复,并进行一些修改。
看看 NSColor类参考 和 NSView 类参考 了解更多信息。
Yes. You can load an image pattern as a color (
[NSColor withPatternImage:[NSImage imageNamed:@"pattern"]]
) and then draw it as you would a regular color:This code will repeat the pattern over the entirety of view, but you can have it simply x-repeat or y-repeat with a little modification.
Take a look at the NSColor Class Reference and the NSView Class Reference to learn more.