【发布时间】:2020-08-21 20:52:37
【问题描述】:
我正在创建一个用于跟踪健康信息的应用程序,我想使用 SF Symbols 中的两个箭头图像。不幸的是,无论我尝试什么,这些符号都不会出现。 我已经使用 Assets 文件夹中的图像测试了代码,这在我创建的 UIImageViews 中似乎没有问题。只有当我尝试使用 UIImage(systemName: ) 时才会遇到问题。
self.calendarView = UIView(frame: CGRect(x: 0, y: self.getCurrentY(), width: UIScreen.main.bounds.width, height: 60))
self.calendarView?.backgroundColor = .white
self.calendarView?.layer.borderColor = UIColor.black.cgColor
self.calendarView?.layer.borderWidth = 1
self.currentDate = UILabel(frame: CGRect(x: self.calendarView!.bounds.width / 4, y: self.calendarView!.bounds.height / 2 - 20, width: self.calendarView!.bounds.width / 2, height: 40))
self.currentDate!.text = "5/6/20"
self.currentDate!.textColor = .black
self.currentDate!.layer.borderColor = UIColor.black.cgColor
self.currentDate?.layer.borderWidth = 1
self.currentDate?.textAlignment = .center
self.calendarView?.addSubview(currentDate!)
//let testImage = UIImage(named: "logotest.jpg")!
let image1 = UIImage(systemName: "arrow.left")!.withTintColor(.blue)
let image2 = UIImage(systemName: "arrow.right")!.withTintColor(.blue)
self.leftArrow = UIImageView(image: image1)
self.rightArrow = UIImageView(image: image2)
self.leftArrow?.frame = CGRect(x: 10, y: 10, width: 40, height: 40)
self.rightArrow?.frame = CGRect(x: UIScreen.main.bounds.width - 50, y: 10, width: 40, height: 40)
self.leftArrow?.layer.borderWidth = 1
self.rightArrow?.layer.borderWidth = 1
self.calendarView!.addSubview(self.leftArrow!)
self.calendarView!.addSubview(self.rightArrow!)
self.contentView.addSubview(self.calendarView!)
更奇怪的是,当我进入断点时,图像实际上显示了!我也附上了这张照片。对此我能得到的任何帮助表示赞赏。谢谢!
【问题讨论】:
-
你的代码够用了……self.contentView的frame是什么?
-
self.calendarView 的框架是什么?我猜他们会超出框架
-
@jawadAli 这是有道理的。 CalendarView 和 contentView(一个 UIScrollView)正在显示,它是 UIImages 没有。我刚刚附上了屏幕的图片,UIImageViews 显示在屏幕的左上角和右上角
-
self.getCurrentY() 总结了添加到 contentView 的视图的大小,因此它知道在滚动视图中添加下一个视图的位置,但知道它的相关性如何
-
@jawadAli 这对我有用,谢谢!!!
标签: ios swift xcode uiimageview sf-symbols