如何在界面构建器中创建重复的图像或模式

时间:2013-12-31 22:44:54

标签: interface-builder xcode5

我一直在使用Xcode 5中的Interface builder,并且无法弄清楚如何创建一个重复的图像,就像这个用红色圈出的区域一样。

enter image description here

因为我是这个新手..是一个重复的图像,这是最好的方法..这在Interface Builder中是否可能?

1 个答案:

答案 0 :(得分:0)

我没有重复图像,而是研究了如何在自定义视图中绘制渐变。这是我的自定义视图的drawRect函数:

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];

    NSRect        bounds = [self bounds];

    NSGradient* aGradient = [[NSGradient alloc]
                             initWithColorsAndLocations:[NSColor colorWithRed:.980f green:.980f blue:.980f alpha:1.0f], (CGFloat)0.0,
                              [NSColor colorWithRed:.956f green:.956f blue:.956f alpha:1.0f], (CGFloat)0.48,
                              [NSColor colorWithRed:.917f green:.917f blue:.917f alpha:1.0f], (CGFloat)0.49,
                              [NSColor colorWithRed:.937f green:.937f blue:.937f alpha:1.0f], (CGFloat)1.0,
                              nil];

    [aGradient drawInRect:bounds angle:-90.0];

    //disable antialias
    [[NSGraphicsContext currentContext] setShouldAntialias: NO];

    NSBezierPath * path = [NSBezierPath bezierPath];
    [path setLineWidth: 0];

    [path  moveToPoint: (NSPoint) { 0, self.bounds.size.height-1 } ];
    [path lineToPoint: (NSPoint){ self.bounds.size.width ,self.bounds.size.height-1 } ];

    [[NSColor colorWithRed:0.647058824f green:0.647058824f blue:0.647058824f alpha:1.0f] set];
    [path stroke];
}