自定义UIBarButtonItem

水深无声 2022-08-19 05:47 17阅读 0赞

//单个自定义按钮

UIButton *button =[UIButtonbuttonWithType:UIButtonTypeCustom];

  1. button.frame =CGRectMake(0, 0, 50, 50);
  2. UIBarButtonItem\*Button = \[\[UIBarButtonItemalloc\] initWithCustomView:button\];
  3. self.navigationItem.leftBarButtonItem = Button;

//多个按钮

  1. UIBarButtonItem \*btn = \[\[UIBarButtonItemalloc\] initWithBarButtonSystemItem:UIBarButtonSystemItemPlaytarget:selfaction:@selector(click:)\];
  2. UIBarButtonItem btnOne = \[\[UIBarButtonItemalloc\] initWithBarButtonSystemItem:UIBarButtonSystemItemPausetarget:selfaction:@selector(click1:)\];
  3. \[self.navigationItemsetRightBarButtonItems:\[NSArrayarrayWithObjects:btn,btnOne,nil\]\];

//自定义View上随意放置button

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(kWidth * 4 / 5, 0, 75, 30)];

  1. //分享按钮
  2. UIButton \*sharebutton = \[UIButton buttonWithType:(UIButtonTypeCustom)\];
  3. sharebutton.frame = CGRectMake(5, 0, 30, 30);
  4. \[view addSubview:sharebutton\];
  5. //收藏按钮
  6. self.collectbutton = \[UIButton buttonWithType:(UIButtonTypeCustom)\];
  7. self.collectbutton.frame = CGRectMake(45, 0, 30, 30);
  8. \[view addSubview:self.collectbutton\];
  9. UIBarButtonItem \*collectItem = \[\[UIBarButtonItem alloc\] initWithCustomView:view\];
  10. self.navigationItem.rightBarButtonItem = collectItem;

发表评论

表情:
评论列表 (有 0 条评论,17人围观)

还没有评论,来说两句吧...

相关阅读