1

看看这张图片...

在此处输入图像描述

我想设计这样的工具栏,每个 UIBarButtonItem 应该用细线分隔。所以我在每个 UIBarButtonItem 之间插入了灵活的空间按钮(这有助于我在方向改变时对齐 UIBarButtonItem),但是如果我为此设置一个图像,它不再充当灵活按钮,而是变为普通的 UIBarbutton。

所以我需要一个带有图像的灵活空间按钮。知道怎么做。(或)如何设计像上面这样的 UIToolbar ......任何帮助都非常感谢。谢谢

4

2 回答 2

0

我想这会对你有所帮助..

UIImage* topImage = [UIImage imageNamed:@"TabBarGradient.png"];

// Create a new image context
UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, topImage.size.height*2), NO, 0.0);

// Create a stretchable image for the top of the background and draw it
UIImage* stretchedTopImage = [topImage stretchableImageWithLeftCapWidth:0 topCapHeight:0];
[stretchedTopImage drawInRect:CGRectMake(0, 0, width, topImage.size.height)];

// Draw a solid black color for the bottom of the background
[[UIColor blackColor] set];
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, topImage.size.height, width, topImage.size.height));

// Generate a new image
UIImage* resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return resultImage;

有关更多详细信息,您可以检查...

http://idevrecipes.com/2011/01/04/how-does-the-twitter-iphone-app-implement-a-custom-tab-bar/

如果没有解决您的问题..让我知道..

于 2013-05-06T10:43:12.550 回答
0

为 UIBarbuttonItem 设置背景图片

UIImage *faceImage = [UIImage imageNamed:@"facebook.png"];
UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];
face.bounds = CGRectMake( 0, 0, faceImage.size.width, faceImage.size.height );
[face setImage:faceImage forState:UIControlStateNormal];
UIBarButtonItem *faceBtn = [[UIBarButtonItem alloc] initWithCustomView:face];
于 2013-05-06T10:39:36.473 回答