2012-08-15 61 views
0

我試圖實現像Mac和iPad上的Safari瀏覽器帶Tab鍵一樣的效果,導航欄和當前選項卡都是其中之一。我如何擴展UINavigationBar/UIToolbar與UIView子類合併爲1?如何將UIToolbar擴展到Safari瀏覽器等其他對象


答:

我創建了自己UIToolbar子類,以及所使用的方法drawRect:(CGRect)rect使UIToolbar相同的顏色作爲我的UIView子類,僅僅是顏色。

- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
    //// General Declarations 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    //// Color Declarations 
    UIColor* gradientColor = [UIColor colorWithRed: 0.916 green: 0.916 blue: 0.916 alpha: 1]; 
    UIColor* gradientColor2 = [UIColor colorWithRed: 0.811 green: 0.811 blue: 0.811 alpha: 1]; 

    //// Gradient Declarations 
    NSArray* gradientColors = [NSArray arrayWithObjects: 
           (id)gradientColor.CGColor, 
           (id)gradientColor2.CGColor, nil]; 
    CGFloat gradientLocations[] = {0, 1}; 
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)gradientColors, gradientLocations); 

    //// Rectangle Drawing 
    UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(-1, 0, 769, 45)]; 
    CGContextSaveGState(context); 
    [rectanglePath addClip]; 
    CGContextDrawLinearGradient(context, gradient, CGPointMake(383.5, -0), CGPointMake(383.5, 45), 0); 
    CGContextRestoreGState(context); 


    //// Cleanup 
    CGGradientRelease(gradient); 
    CGColorSpaceRelease(colorSpace); 
} 

回答

0

我創建了我自己的UIToolbar子類,並使用drawRect:(CGRect)rect方法使UIToolbar與僅用於該顏色的UIView子類具有相同的顏色。

- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
    //// General Declarations 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    //// Color Declarations 
    UIColor* gradientColor = [UIColor colorWithRed: 0.916 green: 0.916 blue: 0.916 alpha: 1]; 
    UIColor* gradientColor2 = [UIColor colorWithRed: 0.811 green: 0.811 blue: 0.811 alpha: 1]; 

    //// Gradient Declarations 
    NSArray* gradientColors = [NSArray arrayWithObjects: 
           (id)gradientColor.CGColor, 
           (id)gradientColor2.CGColor, nil]; 
    CGFloat gradientLocations[] = {0, 1}; 
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)gradientColors, gradientLocations); 

    //// Rectangle Drawing 
    UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(-1, 0, 769, 45)]; 
    CGContextSaveGState(context); 
    [rectanglePath addClip]; 
    CGContextDrawLinearGradient(context, gradient, CGPointMake(383.5, -0), CGPointMake(383.5, 45), 0); 
    CGContextRestoreGState(context); 


    //// Cleanup 
    CGGradientRelease(gradient); 
    CGColorSpaceRelease(colorSpace); 
} 
0

這是自定義外觀的自定義控件。使用具有可伸縮UIImages的UIImageViews並在PNG圖像中重新創建GUI。或者使用Core Graphics來渲染標籤的外觀。 (PaintCode可能有幫助)。

+0

是我自己的畫圖代碼,我用可拉伸的圖像製作標籤,所以它可以使標籤任意大小。即時通訊不太好,我將如何自己做?因爲他們也有uibarbuttonitems,所以我將不得不編碼,以同樣的方式添加我不? – Maximilian 2012-08-15 16:12:08

+0

只需在按鈕的導航欄下方放置標籤欄。 – DrummerB 2012-08-15 16:19:02

+0

我已經有了標籤:P這樣做,只需要知道如何合併它然後用相同的顏色,我嘗試顏色採摘工具和重疊它,並使用顏色,看起來不一樣 – Maximilian 2012-08-15 16:25:15

相關問題