Iphone 如何使NavigationItem UIBarButtonims在视觉上确认触摸?
我有一个UINavigationController,我在其中初始化导航栏(使用MonoTouch): 在随后推到导航控制器上的UIViewController上,我添加了如下按钮:Iphone 如何使NavigationItem UIBarButtonims在视觉上确认触摸?,iphone,uinavigationcontroller,uinavigationbar,xamarin.ios,uibarbuttonitem,Iphone,Uinavigationcontroller,Uinavigationbar,Xamarin.ios,Uibarbuttonitem,我有一个UINavigationController,我在其中初始化导航栏(使用MonoTouch): 在随后推到导航控制器上的UIViewController上,我添加了如下按钮: NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, (s, e) => HandleAddItem()); 但是,当我触摸按钮时,它不会改变颜色/阴影(即动画)来表示它已被触摸。类似的UIBar
NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, (s, e) => HandleAddItem());
但是,当我触摸按钮时,它不会改变颜色/阴影(即动画)来表示它已被触摸。类似的UIBarButtonims添加到另一个视图控制器(普通UIVIewController)上手动创建的UINavigationBar中,并按照我的预期设置动画
当导航栏按钮位于已被推到UINavigationController上的UIViewController上时,如何使其“闪烁”呢?我发现,一旦更改UINavigationBar的
条形样式和色彩,按钮的突出显示状态很可能与默认状态相同。我相信解决这个问题的最好方法是使用从自定义视图创建的uibarbuttonite
UIImage *bgImage = [UIImage imageNamed:@"button-normal.png"];
bgImage = [bgImage stretchableImageWithLeftCapWidth:6.0 topCapHeight:0.0];
UIImage *bgImageHighlighted = [UIImage imageNamed:@"button-highlighted.png"];
bgImageHighlighted = [bgImageHighlighted stretchableImageWithLeftCapWidth:6.0 topCapHeight:0.0];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setBackgroundImage:bgImage forState:UIControlStateNormal];
[myButton setBackgroundImage:bgImageHighlighted forState:UIControlStateHighlighted];
UIBarButtonItem *myItem = [[UIBarButtonItem alloc] initWithCustomView:myButton];
这是一种痛苦,尤其是当你的按钮使用图像而不是标题时。我绝对会建议向苹果提交一份关于这个问题的bug报告
在您的特定情况下,最好只将barStyle
设置为UIBarStyleBlack
,而不使用tintColor
属性。我还幸运地只指定了tintColor
,并将barStyle
设置为UIBarStyleDefault
,只要tintColor
不是黑色。一般来说,黑色的tintColor
效果不太好。当我喜欢它的时候,它就是这样。移除了色彩设置,瞧!魔术非常感谢。
UIImage *bgImage = [UIImage imageNamed:@"button-normal.png"];
bgImage = [bgImage stretchableImageWithLeftCapWidth:6.0 topCapHeight:0.0];
UIImage *bgImageHighlighted = [UIImage imageNamed:@"button-highlighted.png"];
bgImageHighlighted = [bgImageHighlighted stretchableImageWithLeftCapWidth:6.0 topCapHeight:0.0];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setBackgroundImage:bgImage forState:UIControlStateNormal];
[myButton setBackgroundImage:bgImageHighlighted forState:UIControlStateHighlighted];
UIBarButtonItem *myItem = [[UIBarButtonItem alloc] initWithCustomView:myButton];