iOS版11的UIBarButtonItem ImageView的大小错误
问题描述:
你好今天上午与iOS 11,我发现很多我没有与iOS 10.我已经改正了错误最多,除了有两个错误,在顶部的PROFIL图像就在这里iOS版11的UIBarButtonItem ImageView的大小错误
的bug码按钮:
UIImageView* v = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
v.image = img;
v.layer.masksToBounds = YES;
v.layer.cornerRadius = 17.5;
UIBarButtonItem* rightBtn = [[UIBarButtonItem alloc] initWithCustomView:v];
self.navigationItem.rightBarButtonItem = rightBtn;
/////的iOS 10 /////
/////的iOS 11 /////
答
在iOS中11,你必须需要我们的自动布局而不是帧
像下面
myButton.widthAnchor.constraint(equalToConstant: customViewButton.width).isActive = true
myButton.heightAnchor.constraint(equalToConstant: customViewButton.height).isActive = true
答
我解决了这个 用下面的代码:
[v.widthAnchor constraintEqualToConstant:35].active = YES;
[v.heightAnchor constraintEqualToConstant:35].active = YES;
答
我使用UIbutton解决了这个问题。
答
@victor bill的答案就像一个魅力,但我想提一提的是,如果您不先设置按钮的框架,这不起作用。 只有设置宽度和高度锚点使得按钮在我的应用程序中完全消失。
v = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
[v.widthAnchor constraintEqualToConstant:35].active = YES;
[v.heightAnchor constraintEqualToConstant:35].active = YES;
非常感谢您以及如何解决第一个uitableviewcell的填充问题?我使用这个库来标题滚动GSKStretchyHeaderView –