Problem Description:
Normal style:
Show effects on iOS IPhone x:
Watch the left button on the top navbar on iOS 11 This button's picture is not constrained by the size of the set, according to its actual size display, causing the picture dislocation, affecting the interface display effect.
Cause of the problem:
I do not know whether this problem is a IOS11 bug or a new update to IOS11, the problem has not been seen on previous systems. We create a 25*25 button to display the user picture and receive a click event to take action.
We found that:
If the size of the picture is larger than the button setting, the frame of the Set button will not work. The system will use the largest area display. This problem does not occur when the picture size is smaller than the frame of the button being set.
LeftButton = [[cdleftbtn alloc]init]; = YES; = CGRectMake (00); 12.5 ;
[Cdutils displayleftbtnimagewithurlundermyicon:icon.length>0?icon:[cduser currentuser].avatarurl button: LeftButton];
[LeftButton addtarget:self Action: @selector (LEFTBTNCILCK) forcontrolevents:uicontroleventtouchupinside ]; *leftitem = [[Uibarbuttonitem Alloc]initwithcustomview:leftbutton]; = Leftitem;
But because the size of the picture is out of control, we can find another solution
By consulting the relevant data found that there are several ways to solve this problem, first of all, I use the method: Put the button in the view and then use the Uibarbuttonitem initialization method so that the problem does not occur
//add a view to hold BTNUIView *iconbgview = [[UIView alloc]initwithframe:cgrectmake (0,0, -, -)]; LeftButton=[[Cdleftbtn alloc]init]; LeftButton.layer.masksToBounds=YES; Leftbutton.frame= CGRectMake (0,0, -, -); LeftButton.layer.cornerRadius=12.5; [Cdutils displayLeftBtnImageWithUrlUnderMyIcon:icon.length>0?icon:[cduser Currentuser].avatarurl Button:leftbutton]; [Iconbgview Addsubview:leftbutton]; [LeftButton addtarget:self Action: @selector (LEFTBTNCILCK) forcontrolevents:uicontroleventtouchupinside]; Uibarbuttonitem*leftitem =[[Uibarbuttonitem Alloc]initwithcustomview:iconbgview]; Self.navigationItem.leftBarButtonItem= Leftitem;
The above method can solve this problem, but the specific reason and the principle are not clear but can be used to solve the problem personally feel that it is again forced to constrain the size of the BTN to make its picture constrained
Alternatively, you can avoid this problem by creating a button in the recommended way of IOS
Uibarbuttonitem *item = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@ "d" ] style:uibarbuttonitemstyledone target:self Action: @selector (Basereturnaction)]; = [Uicolor whitecolor]; = Item;
The authenticity of this method is not examined
Resources
reference materials for IOS 11 adaptation:
Cheny's Blog
Look at my big eyes.
iOS11 navigationbar on button picture Set frame Invalid unconstrained problem solved