【发布时间】:2017-10-16 17:41:33
【问题描述】:
在我从 Xcode 9 构建我的应用程序后,UIBarbutton 项目不响应点击。它在 Xcode 8 上工作。
显然发现了下面这篇文章中描述的问题.. (UIBarButtonItem not clickable on iOS 11 beta 7?)
问题是我添加了帖子中解释的约束,但仍然无法正常工作。有人可以看看我的代码并告诉我我做错了什么吗?
UIImage* image = [UIImage imageNamed:@"test.png"];
CGRect frame = CGRectMake(0, 0, 30, 30);
UIButton* someButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[someButton setImage:image forState:UIControlStateNormal];
[someButton setFrame:frame];
[someButton setShowsTouchWhenHighlighted:YES];
[someButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
NSLayoutConstraint * widthConstraint = [someButton.widthAnchor constraintEqualToConstant:30];
NSLayoutConstraint * HeightConstraint =[someButton.heightAnchor constraintEqualToConstant:30];
[widthConstraint setActive:YES];
[HeightConstraint setActive:YES];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:someButton];
self.toolbar.items = [NSArray arrayWithObjects:item, nil];
【问题讨论】:
标签: ios uibarbuttonitem ios11 xcode9 clickable