First, the problem some needs need to use the button and label, and need to align the same line, such as a cue bar, there is a part of the tip text is not clickable, but some of the text can be clicked and jump. Thus throughSizewithattributes or other system method calculates the string size, and then sets the size of the button to the size of the corresponding title, the label aligns the button, and the size is set to the size of the corresponding text string. In the case of coordinates and size, the font is misaligned:Second, reproduce the problem: Create a button and a label, the coordinates are as follows:<UIButton:0x7c49ac50; frame = (0; 199.131 35.8008); opaque = NO; layer = <calayer:0x7c49adb0>> ; <UILabel:0x7c15efc0; frame = (199.131; 199.131 35.8008); text = ' search. 123 Search '; userinteractionenabled = NO; layer = <_UILabelLayer:0x7c15f230>> Study found that the Y coordinate of the two view is the same, the output of the background color and not see the two view background area is different, further found that when the value of x, Y is also a floating point, the deviation will be greater, and then try to take the value of the frame through the whole to find two view alignment, such as: third, conclusion The button and label internally handle floating-point coordinates differently, and if you need a different view alignment, and you use the frame layout, make sure that the value of the frame is an integer.
Ios-frame layout floating-point numbers cause alignment issues