xやy、あるいはその両方を繰り返すことができるビュー内にパターン(グリッドなど)を表示することはできますか?のようなCSSの種類:Objective-c:背景パターンを表示
background-image:url(pattern.png); background-repeat:repeat; //またはrepeat-x、repeat-y、繰り返しなし;
xやy、あるいはその両方を繰り返すことができるビュー内にパターン(グリッドなど)を表示することはできますか?のようなCSSの種類:Objective-c:背景パターンを表示
background-image:url(pattern.png); background-repeat:repeat; //またはrepeat-x、repeat-y、繰り返しなし;
はい。あなたは色([NSColor withPatternImage:[NSImage imageNamed:@"pattern"]]
)などの画像パターンをロードしますが、通常の色と同じようにそれを描くことができます:
- (void)drawRect:(NSRect)dirtyRect {
...
// Load the image through NSImage and set it as the current color.
[[NSColor colorWithPatternImage:[NSImage imageNamed:@"pattern"]] set];
// Fill the entire view with the image.
[NSBezierPath fillRect:[self bounds]];
...
}
このコードは、ビュー全体にパターンを繰り返しますが、あなたは、単にそれを持つことができX-リピートまたはyリピートを少し変更してください。
の詳細を学ぶためにNSColor Class ReferenceとNSView Class Referenceを見てみましょう。
スニペットありがとう! – PruitIgoe
問題ありません。それがうれしかった。 –
次のコード意志タイルの背景画像:
- (void) viewDidLoad {
[[self view] setBackgroundColor: [[UIColor alloc] initWithPatternImage: [UIImage imageNamed: @"background.png"]]];
[super viewDidLoad];
}
のNSViewまたはUIViewの? –