barItem 設(shè)置圖片變成純色了描函?
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageWithData:data]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:nil];
參考: https://blog.csdn.net/anan890624/article/details/53718949
將圖放入按鈕再放入barItem
UIButton *leftCustomButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
[leftCustomButton.widthAnchor constraintEqualToConstant:35].active = YES;
[leftCustomButton.heightAnchor constraintEqualToConstant:35].active = YES;
[leftCustomButton setImage:[UIImage imageNamed:@"defaultImage"] forState:UIControlStateNormal];
UIBarButtonItem * leftButtonItem =[[UIBarButtonItem alloc] initWithCustomView:leftCustomButton];
self.navigationItem.leftBarButtonItems = @[self.headerIconItem];
參考:
http://www.cocoachina.com/bbs/read.php?tid-1726773.html
設(shè)置邊距
leftBarButtonItem設(shè)置左邊距昼丑,rightBarButtonItem設(shè)置右邊距
不支持iOS11
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 44)];
[backButton addTarget:self action:@selector(navigationBackButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[backButton setBackgroundImage:[UIImage imageNamed:@"fanHuiC60.88"] forState:UIControlStateNormal];
UIBarButtonItem *backBtnI = [[UIBarButtonItem alloc] initWithCustomView:backButton];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -17;
self.navigationItem.leftBarButtonItems = @[negativeSpacer,backBtnI];
參考:
https://blog.csdn.net/dcjxrk/article/details/50766322