UIButton *button1 = [FGWButton creatButtonWithtarget:self sel:@selector(press)];
UIBarButtonItem *leftButon = [[UIBarButtonItem alloc] initWithCustomView :button1];
UIBarButtonItem *fixedButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
self.navigationItem.leftBarButtonItems = @[fixedButton, leftButon];
+ (UIButton *)creatButtonWithtarget:(id)target sel:(SEL)sel {
UIButton *button = nil;
//创建图片按钮
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 40, 40);
[button setImage:[UIImage imageNamed:@"右箭头.png"] forState:UIControlStateNormal];
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[button addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
return button;
}
本文介绍如何在iOS应用中使用Objective-C自定义导航栏左侧按钮,并通过UIButton创建带图片的按钮,设置按钮点击事件。
&spm=1001.2101.3001.5002&articleId=54911247&d=1&t=3&u=3308136ec89f40e8a7ea3dc650d1c427)
242

被折叠的 条评论
为什么被折叠?



