gpt4 book ai didi

ios5 - 如何在 ios5 中自定义 UIBarButtonItem

转载 作者:行者123 更新时间:2023-12-01 07:58:17 27 4
gpt4 key购买 nike

我想自定义 UIBarButtonItem,这是我的代码。

在ios4.3可以,但是ios5,就很奇怪了。uibarbuttonitem消失不见了,但是你点击它还是有效果的。因为是透明的。

我需要帮助,如何使uibarbuttonitem显示。谢谢

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 0, 50, 30);
[btn setBackgroundImage:[UIImage imageNamed:@"btnRegister.png"] forState:UIControlStateNormal];
[btn setTitle:@"register" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(registerClick:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.rightBarButtonItem = item1;

最佳答案

这里有一个关于 iOS 5 中新的自定义功能的很棒的教程:http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5

这是该网站的一份代码副本,用于处理 UIBarButtonItems 的自定义,非常不言自明:

UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
UIImage *button24 = [[UIImage imageNamed:@"button_textured_24"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];

[[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:button24 forState:UIControlStateNormal
barMetrics:UIBarMetricsLandscapePhone];

[[UIBarButtonItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0],
UITextAttributeTextColor,
[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"AmericanTypewriter" size:0.0],
UITextAttributeFont,
nil]
forState:UIControlStateNormal];

关于ios5 - 如何在 ios5 中自定义 UIBarButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7950644/

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