SDAutoLayout
SDAutoLayout copied to clipboard
引入第三方sdk后setSingleLineAutoResizeWithMaxWidth计算label宽度时异常
使用SDAutoLayout对Label自动布局,之前Label显示都是正常的,引入了一个第三方Framework之后,就显示不全了。
引入第三方Framework之前显示效果
引入第三方Framework之后显示效果
代码如下:
UILabel *autoWidthlabel = [UILabel new];
autoWidthlabel.backgroundColor = [[UIColor orangeColor] colorWithAlphaComponent:0.5];
_autoWidthLabel = autoWidthlabel;
autoWidthlabel.font = [UIFont systemFontOfSize:14];
autoWidthlabel.text = @"Hello, 2Locksmiths!";
[self.view addSubview:autoWidthlabel];
autoWidthlabel.sd_layout
.rightSpaceToView(self.view, 10)
.heightIs(20)
.bottomSpaceToView(self.view, 50);
// 用Label显示Hello, 2Locksmiths!的内容
[autoWidthlabel setSingleLineAutoResizeWithMaxWidth:200];
想着应该是计算宽度时出来问题,于是在UIView+SDAutoLayout.m源码的- (void)layoutAutoWidthWidthView:(UIView *)view model:(SDAutoLayoutModel *)model{} 函数里打印了一些log
// qqqrect.size.width: 126.362305, width: 200.000000
label.width_sd = rect.size.width + 0.1; // 出现差异的位置
NSLog(@"label.width_sd: %f", label.width_sd);
// label.width_sd: 126.000000 // 引入第三方组件后,这里是什么原因造成的呢?
// label.width_sd: 126.462305 // 引入第三方组件前
引入第三方组件之前计算的值:
引入第三方组件之后计算的值:

这是什么原因导致的呢?
引入的第三方组件

加个1像素的宽度😝