[英]iOS - How to custom vertical position of navigation back bar item
我有这样的导航栏设计。 我已经准备好增加导航栏的高度,但是如何设置“后退”按钮图像的位置并使标题左对齐?
#import "UINavigationBar+Custom.h"
@implementation UINavigationBar (Custom)
- (CGSize)sizeThatFits:(CGSize)size {
CGRect rec = self.frame;
CGRect screenRect = [[UIScreen mainScreen] bounds];
rec.size.width = screenRect.size.width;
rec.size.height = 77;
return rec.size;
}
@end
NavBar图片设计
现实
更新:我的代码添加了后退栏按钮
- (void)viewDidLoad {
[super viewDidLoad];
[self configNavBar];
}
- (void)configNavBar {
// -- Config NavigationBar Background --
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;
// -- Navigator title font --
NSDictionary *titleAttributes = @{
NSFontAttributeName :FONT_NAVIGATION_TITLE_BAR,
NSForegroundColorAttributeName : [Utils colorWithHexString:@"#0f385a"] };
[self.navigationController.navigationBar setTitleTextAttributes:titleAttributes];
// -- Back button color --
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
UIImage *myImage = [UIImage imageNamed:@"ic_arrow_back"]; //set your backbutton imagename
UIImage *backButtonImage = [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// now use the new backButtomImage
[[UINavigationBar appearance] setBackIndicatorImage:backButtonImage];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backButtonImage];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-0.f, -0)
forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundVerticalPositionAdjustment:40 forBarMetrics:UIBarMetricsDefault];
// -- Empty back title --
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButtonItem];
}
试试下面的代码UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image"] style:UIBarButtonItemStylePlain target:self action:@selector(action)]; [self.navigationItem setLeftBarButtonItem:barButtonItem];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image"] style:UIBarButtonItemStylePlain target:self action:@selector(action)]; [self.navigationItem setLeftBarButtonItem:barButtonItem];
。 并正确格式化图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.