我试图实现像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);
}
是我自己的画图代码,我用可拉伸的图像制作标签,所以它可以使标签任意大小。即时通讯不太好,我将如何自己做?因为他们也有uibarbuttonitems,所以我将不得不编码,以同样的方式添加我不? – Maximilian 2012-08-15 16:12:08
只需在按钮的导航栏下方放置标签栏。 – DrummerB 2012-08-15 16:19:02
我已经有了标签:P这样做,只需要知道如何合并它然后用相同的颜色,我尝试颜色采摘工具和重叠它,并使用颜色,看起来不一样 – Maximilian 2012-08-15 16:25:15