美文网首页
iOS修改导航栏按钮图片大小

iOS修改导航栏按钮图片大小

作者: wxw_威 | 来源:发表于2021-05-08 22:22 被阅读0次

[shareButton.widthAnchor constraintEqualToConstant:25].active = YES;
[shareButton.heightAnchor constraintEqualToConstant:25].active = YES;

UIImage *shareImg = [UIImage imageNamed:@"YQCRMResource.bundle/share"];
UIImage *editImg = [UIImage imageNamed:@"YQCRMResource.bundle/edit"];
// 分享
UIButton *shareButton=[UIButton buttonWithType:UIButtonTypeCustom];
shareButton.frame = CGRectMake(0, 0, 40, 40);
[shareButton.widthAnchor constraintEqualToConstant:25].active = YES;
[shareButton.heightAnchor constraintEqualToConstant:25].active = YES;
[shareButton setBackgroundImage:shareImg forState:UIControlStateNormal];
[shareButton addTarget:self action:@selector(shareItemClick:) forControlEvents:UIControlEventTouchUpInside];
// 编辑
UIButton *editButton=[UIButton buttonWithType:UIButtonTypeCustom];
[editButton addTarget:self action:@selector(editItemClick:) forControlEvents:UIControlEventTouchUpInside];
[editButton setBackgroundImage:editImg forState:UIControlStateNormal];
editButton.frame=CGRectMake(0, 0, 40, 40);
[editButton.widthAnchor constraintEqualToConstant:25].active = YES;
[editButton.heightAnchor constraintEqualToConstant:25].active = YES;

UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithCustomView:shareButton];
UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithCustomView:editButton];
  
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: shareItem, editItem,nil]];

相关文章

网友评论

      本文标题:iOS修改导航栏按钮图片大小

      本文链接:https://www.haomeiwen.com/subject/akppdltx.html