Objective c iOS 11上的UIButton点击区域变小

Objective c iOS 11上的UIButton点击区域变小,objective-c,uibutton,ios11,xcode9,uiedgeinsets,Objective C,Uibutton,Ios11,Xcode9,Uiedgeinsets,我注意到UIButton的点击区域从iOS 11开始变小了。为了确认这一点,我在其子视图上注释掉了所需的背景色,并在按钮本身上添加了紫色 iOS 10.0.3(根据需要显示按钮) iOS 11.1(水龙头面积变小) 我的代码如下 UIImage *ringImage = [UIImage imageNamed:@"ball20r"]; UIEdgeInsets insets = UIEdgeInsetsMake(10,10,10,10); //padding UIImage *stretch

我注意到UIButton的点击区域从iOS 11开始变小了。为了确认这一点,我在其子视图上注释掉了所需的背景色,并在按钮本身上添加了紫色

iOS 10.0.3(根据需要显示按钮)

iOS 11.1(水龙头面积变小)

我的代码如下

UIImage *ringImage = [UIImage imageNamed:@"ball20r"];
UIEdgeInsets insets = UIEdgeInsetsMake(10,10,10,10); //padding
UIImage *stretchableImage = [ringImage resizableImageWithCapInsets:insets];

UIImageView *imageView   = [[UIImageView alloc]initWithImage:stretchableImage];
// imageView.backgroundColor = backgroundColor; //disabled for testing
imageView.frame = CGRectMake(0, 0, label.frame.size.width + 16.0, label.frame.size.height + 16.0);
[imageView addSubview:label];


label.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *viewsDictionary = @{@"label":label};
NSArray *constraint_H = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(8)-[label]-(8)-|"
                                                                options:0
                                                                metrics:nil
                                                                  views:viewsDictionary];
NSArray *constraint_V = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(8)-[label]-(8)-|"
                                                                options:0
                                                                metrics:nil
                                                                  views:viewsDictionary];
[imageView addConstraints:constraint_H];
[imageView addConstraints:constraint_V];


UIButton *calendarButton = [UIButton buttonWithType:UIButtonTypeCustom];
[calendarButton addTarget:self action:@selector(chooseACalendarToSave) forControlEvents:UIControlEventTouchUpInside];
calendarButton.frame = imageView.frame;
[calendarButton addSubview:imageView];

//added for testing only
calendarButton.backgroundColor = [UIColor purpleColor];

_calendarButton = [[UIBarButtonItem alloc]initWithCustomView:calendarButton];
如何使iOS区域与iOS 10.0.3及更早版本一样? 谢谢你的帮助。

答案就在这里。

我一插入上述代码,按钮就开始按预期工作。谢谢。

答案就在这里。

我一插入上述代码,按钮就开始按预期工作。多谢各位

 if (@available(iOS 9, *)) {
      [cButton.widthAnchor constraintEqualToConstant: standardButtonSize.width].active = YES;
      [cButton.heightAnchor constraintEqualToConstant: standardButtonSize.height].active = YES;
 }