解决iOS11中navigationBar上使用initWithCustomView按钮图片错位 frame无效

来源:互联网 发布:hibernate访问数据库 编辑:程序博客网 时间:2024/06/06 01:23

在iOS11上当使用如下代码设置时

   UIButton *shareButton = [UIButton buttonWithType:(UIButtonTypeCustom)];    shareButton.frame = CGRectMake(0, 0, 30, 30);    shareButton.backgroundColor = [UIColor blueColor];    [shareButton setImage:[UIImage imageNamed:@"mv_actionIconSaveToAlbum"]  forState:(UIControlStateNormal)];    UIBarButtonItem *rightBtnItem = [[UIBarButtonItem alloc] initWithCustomView:shareButton];    self.navigationItem.rightBarButtonItem = rightBtnItem;

如果图片大小大于按钮设置的大小 ,设置的button的frame将不起作用。系统将采用最大区域展示。图片大小小于设置的button的frame时 不会出现这个问题。

原创粉丝点击