How to place a UIImage in Navigationbar such that

2019-01-29 08:15发布

enter image description hereenter image description hereI would like to place a logo/image in the left side of NavigationBar. I try this in codes, but it is not worked properly.

UIImage *logo = [UIImage imageNamed:@"logo.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: logo];
imageView.frame = CGRectMake(2, 2, 40, 40);
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:logo];

I try with view to be placed first then place image as UIImageView but alignment is not good. And moreover view appears to be white space while run the code..

7条回答
戒情不戒烟
2楼-- · 2019-01-29 09:15
UIBarButtonItem *logoItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:nil];
UIBarButtonItem *logoItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItem target:self action:nil];

NSArray *actionButtonItems = @[logoItem1, logoItem2];
self.navigationItem.rightBarButtonItems = actionButtonItems;
查看更多
登录 后发表回答