2017-11-09 8 views
1

내 UIButton의 탭 영역이 iOS 11부터 작아지는 것을 확인했습니다. 확인하기 위해 하위 뷰에서 원하는 배경색을 주석 처리하고 버튼 자체에 자주색을 삽입했습니다.iOS 11에서 UIButton 탭 영역이 작아졌습니다.

는 아이폰 OS 10.0.3 (원하는대로 표시 버튼) enter image description here

아이폰 OS 11.1 (탭 영역이 작은있어) enter image description here

내 코드는 다음과 같다.

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 이하와 같이 만들려면 어떻게해야합니까? 도움 주셔서 감사합니다.

답변

0

답변은 여기에 있습니다. 예상대로 iOS 11 UIBarButtonItem images not sizing

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

는 최대한 빨리 코드 위에 삽입으로, 버튼이 작동하기 시작했다. 고맙습니다.