gpt4 book ai didi

ios - UIToolBar 背景透明

转载 作者:行者123 更新时间:2023-12-01 17:21:35 29 4
gpt4 key购买 nike

我正在尝试放置 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;

那个 UIToolBar的背景色是默认的蓝色。
但是我需要工具栏应该是清晰的颜色,以便导航栏的背景图像也应该出现在该工具栏中。

请建议我。

最佳答案

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

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];

关于ios - UIToolBar 背景透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9389540/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com