iOSナビゲーションバーBarButtonItem間隔(item間および画面エッジ間)で変更できない問題の処理方法
2627 ワード
次のコードは私がWKWebViewブラウザをカスタマイズするときに使ったものです.ここはGithubアドレスです.必要なものがあれば見てください.
足りないところ、よろしくお愿いします.
#pragma mark BarButtonItem
- (void)setBarButtonItem
{
// imageInset item item
//
self.leftBarButton = [[UIBarButtonItem alloc]initWithCustomView:[self addItemWithImage:@"back_item"
imageInset:UIEdgeInsetsMake(0, -10, 0, 10)
size:CGSizeMake(28, 28)
action:@selector(selectedToBack)]];
//
self.leftBarButtonSecond = [[UIBarButtonItem alloc]initWithCustomView:[self addItemWithImage:@"close_item"
imageInset:UIEdgeInsetsMake(0, -15, 0, 15)
size:CGSizeMake(28, 28)
action:@selector(selectedToClose)]];
self.navigationItem.leftBarButtonItems = @[self.leftBarButton];
if (@available(iOS 11,*)) {
NSLog(@"** iOS 11 **");
}else{
NSLog(@"** Not iOS 11 **");
}
//
UIBarButtonItem *reloadItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"reload_item"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(selectedToReloadData)];
self.navigationItem.rightBarButtonItems = @[reloadItem];
}
#pragma mark item
- (UIButton *)addItemWithImage:(NSString *)imageName imageInset:(UIEdgeInsets)inset size:(CGSize)itemSize action:(SEL)action {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image = [UIImage imageNamed:imageName];
button.frame = CGRectMake(0, 0, itemSize.width, itemSize.height);
[button setImageEdgeInsets:inset];
[button setImage:image forState:UIControlStateNormal];
[button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
button.titleLabel.font = [UIFont systemFontOfSize:16];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = rightItem;
return button;
}
足りないところ、よろしくお愿いします.