如何在ios5中定制uibarbuttonite
我想要定制uibarbuttonite,这是我的代码 在ios4.3中它可以工作,但在ios5中,它非常奇怪。 uibarbuttonite消失在视线之外,但是你点击它仍然有效果,因为它是透明的 我需要你的帮助,如何制作这个UIBarbuttonim的展示。谢谢如何在ios5中定制uibarbuttonite,ios5,uibarbuttonitem,Ios5,Uibarbuttonitem,我想要定制uibarbuttonite,这是我的代码 在ios4.3中它可以工作,但在ios5中,它非常奇怪。 uibarbuttonite消失在视线之外,但是你点击它仍然有效果,因为它是透明的 我需要你的帮助,如何制作这个UIBarbuttonim的展示。谢谢 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.frame = CGRectMake(0, 0, 50, 30); [btn setBackground
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;
我的问题和这个类似。在我的情况下,按钮显示为“无启用”。当你把它放进去的时候,它仍然有效果。一个小的解决办法是改变按钮的颜色为白色,但我正在寻找更好的方法:) 我的代码是:
buttonImage = [UIImage imageNamed:@"top_icon_share.png"];
UIButton *buttonShare = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height)];
[buttonShare setBackgroundImage:buttonImage forState:UIControlStateNormal];
[buttonShare addTarget:self action:@selector(buttonSharePressed)
forControlEvents:UIControlEventTouchUpInside];
[buttonShare setShowsTouchWhenHighlighted:YES];];
UIBarButtonItem *buttonBarShare = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"top_icon_share.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonSharePressed:)];
关于iOS 5中的新自定义功能,这里有一个很棒的教程: 下面是该网站的一份代码副本,该代码涉及到UIBarbuttonims的定制,它非常不言自明:
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];