2011-01-09 4 views
2

x 또는 y 또는 둘 다 반복 될 수있는보기에서 패턴 (예 : 격자)을 사용할 수 있습니까? 같은 종류의 CSS :Objective-c : 배경 패턴보기

background-image : url (pattern.png); background-repeat : 반복; // 또는 repeat-x, repeat-y, 반복 없음;

+0

는 NSView 또는 UIView의? –

답변

4

예. 당신은 컬러로 ([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 축 할 수 있습니다 repeat 또는 y-repeat를 조금 수정하면됩니다.


은 자세한 내용을 보려면 NSColor Class ReferenceNSView Class Reference를 살펴 보자.

+0

발췌 해 주셔서 감사합니다! – PruitIgoe

+0

문제 없습니다. 다행 했어. –

7

다음 코드 타일 것입니다 배경 이미지 :

- (void) viewDidLoad { 
    [[self view] setBackgroundColor: [[UIColor alloc] initWithPatternImage: [UIImage imageNamed: @"background.png"]]]; 
    [super viewDidLoad]; 
}