【问题标题】:how to make a repeating image or pattern in interface builder如何在界面生成器中制作重复的图像或图案
【发布时间】:2013-12-31 22:44:54
【问题描述】:

我一直在玩 Xcode 5 中的界面生成器,但不知道如何创建像这个用红圈圈起来的区域一样的重复图像..

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

【问题讨论】:

    标签: interface-builder xcode5


    【解决方案1】:

    我没有重复图像,而是研究了如何在自定义视图中绘制渐变。这是我的自定义视图的 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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      • 2011-10-07
      • 1970-01-01
      相关资源
      最近更新 更多