swift开发常见问题汇总

@高效码农  December 30, 2021

一、tabBarItem.selectedImage 设置选中图片无效

未命名.gif

修改前代码
my.tabBarItem.selectedImage = UIImage(named: "my_selected")
修改后代码 解决方案:增加渲染方式.alwaysOriginal
my.tabBarItem.selectedImage = UIImage(named: "my_selected")?.withRenderingMode(.alwaysOriginal)

二、报错信息:because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.

解决方案:将子视图在约束之前添加到主视图中

三、导入自定义字体无效

导入方法:https://juejin.cn/post/6844903529623060488

如果按照步骤还是无效验证一下:是否和现有字体冲突;验证方法为将字体加入到字体册
2022-01-06T03:38:31.png
出现上图说明字体冲突

四、UIView加圆角 layer.cornerRadius 不管用

解决方案:视图上的子视图,如果超出父视图的部分就截取掉,即设置

UIView.clipsToBounds = true

五、报错信息:Trailing closure passed to parameter of type 'Visibility' that does not acce

解决方案:

1、查看是否{ ( 是否关闭;
2、查看.toolbar { 是否有过期代码



评论已关闭