1

I notice the tap area for my UIButton got smaller since iOS 11. To confirm, I commented out the desired background color on its subviews and put purple color on the button itself.

iOS 10.0.3 (Button shown as desired) enter image description here

iOS 11.1 (Tap area got smaller) enter image description here

My code follows.

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];

How can I make the area for iOS just like iOS 10.0.3 and earlier? Thanks for your help.

tsuyoski
  • 614
  • 5
  • 22

1 Answers1

0

The answer is here. iOS 11 UIBarButtonItem images not sizing

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

As soon as I inserted above code, the button started working as expected. Thank you.

tsuyoski
  • 614
  • 5
  • 22