UIToolBar背景透明

Bha*_*thi 1 uitoolbar uinavigationcontroller ios

我试图把UIToolBarUINavigationBar.

   UIToolbar* tempFontSizeToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(kPaginationToolBarOriginX,kPaginationToolBarOriginY,kPaginationToolBarWidth,kPaginationToolBarHeight)];

    tempFontSizeToolBar.backgroundColor = [UIColor clearColor];

  // create the array to hold the buttons, which then gets added to the toolbar

   NSMutableArray* buttons = [[NSMutableArray alloc] init];
  [tempFontSizeToolBar setTranslucent:YES];
  UIBarButtonItem *fontSizeBarButtonItem;

  fontSizeBarButtonItem = [[UIBarButtonItem alloc]
                         initWithImage:[UIImage imageNamed:KpreviousPageIcon] style:UIBarButtonItemStylePlain target:self action:@selector(movePreviousPage:)];

  [buttons addObject:fontSizeBarButtonItem];

  [fontSizeBarButtonItem release];fontSizeBarButtonItem = nil;

  fontSizeBarButtonItem = [[UIBarButtonItem alloc]
                         initWithImage:[UIImage imageNamed:KnextpageIcon] style:UIBarButtonItemStylePlain  target:self action:@selector(moveNextPage:)];

  [buttons addObject:fontSizeBarButtonItem];

  [fontSizeBarButtonItem release];fontSizeBarButtonItem = nil;

// stick the buttons in the toolbar
  [tempFontSizeToolBar setItems:buttons animated:NO];

  [buttons release];buttons = nil;

  UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:tempFontSizeToolBar];

  self.navigationItem.rightBarButtonItem = rightBarItem;
Run Code Online (Sandbox Code Playgroud)

它的背景颜色UIToolBar是默认的蓝色.但我需要工具栏应该是清晰的颜色,以便NavigationBar的背景图像也应该出现在该工具栏中.

请建议我.

jd.*_*jd. 5

要使工具栏透明,请使用以下命令:

const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];

[self.toolbar setBackgroundImage:maskedImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)