我试图在Mac和iPad上实现像Safari一样的效果,使用导航栏和当前标签。如何扩展UINavigationBar / UIToolbar以与UIView子类合并为1?
答案:
我创建了自己的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 :(得分:0)
这是一个具有自定义外观的自定义控件。将UIImageViews与可伸缩的UIImages一起使用,并在PNG图像中重新创建GUI。或使用Core Graphics渲染选项卡的外观。 (PaintCode可能对此有帮助。)
答案 1 :(得分: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);
}