Open dev-zuo opened 5 years ago
使用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像素的宽度😝
引入第三方Framework之前显示效果
引入第三方Framework之后显示效果
代码如下:
想着应该是计算宽度时出来问题,于是在UIView+SDAutoLayout.m源码的- (void)layoutAutoWidthWidthView:(UIView )view model:(SDAutoLayoutModel )model{} 函数里打印了一些log
引入第三方组件之前计算的值:
引入第三方组件之后计算的值:
![image](https://user-images.githubusercontent.com/28626865/53883059-f39a9180-4052-11e9-919f-c103831cc02b.png)
这是什么原因导致的呢?
引入的第三方组件![image](https://user-images.githubusercontent.com/28626865/53883272-7de2f580-4053-11e9-8ff3-6a87174655d0.png)