0
我已经使用SnapKit定位了UIView,并且需要找到添加阴影的方法。因为我将视图相对于其他UIViews进行了定位,所以我没有视图的高度,宽度或起始坐标。我如何添加一个阴影到使用SnapKit自动布局定位的UIView。定位UIView的代码是这样的:将阴影添加到使用SnapKit定位的UIView
tableViewBackground.snp.makeConstraints{ (make) -> Void in
make.width.lessThanOrEqualToSuperview()
make.height.lessThanOrEqualToSuperview()
make.right.equalToSuperview().offset(-20)
make.left.equalToSuperview().offset(20)
make.bottom.equalToSuperview().offset(-20)
make.top.equalTo(poiLabel.snp.bottom).offset(20)
}
为什么不使用'layer'阴影设置,就像任何其他观影? – matt
@matt我已经尝试使用'tableViewBackground.layer.shadowPath = UIBezierPath(rect:tableViewBackground.bounds).cgPath'。问题是'tableViewBackground.bounds'等于[0,0,0,0],因为视图是使用snapkit – SmedleyDSlap
定位的。这仅仅表明你做得太快了。等到视图_has_被定位后,让你有实际的边界。 – matt