[英]Custom ios app nav bar buttons
I'm having problems to create an custom nav bar like the Uber app . 我在创建类似Uber应用程序的自定义导航栏时遇到问题。
I'm setting my button background image to: 我将按钮背景图像设置为:
UIImage *button44 = [[UIImage imageNamed:@"navButtonAdd"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIBarButtonItem appearance] setBackgroundImage:button44 forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
But If I remove the text from the button on the xcode interface it disappear the image as well and also there is a padding on the right that starts repeating my image again. 但是,如果我从xcode界面上的按钮中删除了文本,则图像也会消失,并且右侧还有一个填充,可以再次开始重复我的图像。
Does anyone know how I could fix it? 有谁知道我该如何解决?
This is the image I'm trying to use as a button 这是我要用作按钮的图像
Thanks in advance 提前致谢
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"button"]]];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"uberbar.png"] forBarMetrics:UIBarMetricsDefault];
If I'm not mistaken you need a custom view on the UIBarButtonItem. 如果我没记错的话,则需要UIBarButtonItem上的自定义视图。 So you could get the appearance proxy, set the image for the controller, or instead customize the image directly.
因此,您可以获得外观代理,为控制器设置图像,或者直接自定义图像。 That padding is a matter of photoshopping the graphic and set its dimensions correctly.
填充仅需对图片进行photoshop处理并正确设置其尺寸即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.