1.navigationbar上的左右按钮的位置的改变
图1如果想要图示1的效果代码如下:
UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[settingBtn setImage:[UIImage imageNamed:@"铃铛"] forState:UIControlStateNormal];
settingBtn.frame = CGRectMake(0, 0, 60, 40);
[settingBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightBar = [[UIBarButtonItem alloc]initWithCustomView:settingBtn];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -20;
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,rightBar,nil];
图2
如果想要图示2的效果代码如下
UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"三横线"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBtnClick:)];
self.navigationItem.leftBarButtonItem = left;
(欢迎大家对不合适的地方进行指正,看完觉得有帮到你给点个赞👍吧)
网友评论