1

I have recently migrated to VIPER and while using this type of architecture came up with such question:

For instance, I have in designs long(2000pt height) UI with over 50 interface elements like labels, buttons, views, collections and so on and I need to add round corners and shadows to them.

Where should I configure its appearance? Should it be in View, or somehow in Presenter?

So far I have extended UIView to create a method to drop shadow.

Right now, what I have in View module is:

 override func viewDidLayoutSubviews() {
    doctorsNearCollection.backgroundColor = UIColor(white: 1, alpha: 0)
    newsMayBeInterestedCollection.backgroundColor = UIColor(white: 1, alpha: 0)
    recentSavedNewsCollection.backgroundColor = UIColor(white: 1, alpha: 0)
    setupCharts()
    
    scheduleMetting.dropShadow()
    scheduleMetting.layer.cornerRadius = 5
    
    monthlyPerformaceBackground.dropShadow()
    monthlyPerformaceBackground.layer.cornerRadius = 5
    
    firstMeeting.dropShadow()
    firstMeeting.layer.cornerRadius = 5
    firstMeetingNumber.layer.cornerRadius = self.firstMeetingNumber.frame.size.width / 2
    
    secondMeeting.dropShadow()
    secondMeeting.layer.cornerRadius = 5
    secondMeetingNumber.layer.cornerRadius = self.secondMeetingNumber.frame.size.width / 2
    
    thirdMeeting.dropShadow()
    thirdMeeting.layer.cornerRadius = 5
    thirdMeetingNumber.layer.cornerRadius = self.thirdMeetingNumber.frame.size.width / 2
    
    seeAllMeetings.dropShadow()
    seeAllMeetings.layer.cornerRadius = 5
    
    searchForDoctors.dropShadow()
    searchForDoctors.layer.cornerRadius = 5
    
    seeAllSavedNews.dropShadow()
    seeAllSavedNews.layer.cornerRadius = 5
}

Is this a good practice? I'm interested in setting up commonality among the appearance of views as factored out from other methods. It seems more or less clear to me. Thanks in advance.

4

1 回答 1

1
  • https://TheSwiftDev.com/the-ultimate-viper-architecture-tutorial中所述,UI 细节和构造必须隔离在视图区域中,并且永远不会出现在演示者区域中,因为视图区域处理/隔离所有 UI 细节/概念为内部事务,而演示者区域将所有纯应用程序域详细信息/概念作为内部事务处理/隔离。
  • 本着永不言败的精神,UI 元素的“圆角和阴影”唯一会出现在演示者区域的情况是,如果应用程序的应用程序域本身就是一个 UI 生成器或 UI-编辑器或 UI 设计器工具,其中某些下游(应用程序的)UI(即,不是应用程序的 UI)是此应用程序的应用程序域。因此,除非您的应用程序是用于 UI 开发的 UI 设计环境,否则 UI 内容永远不会超出视图区域(即使在例外情况下,它也是其他应用程序的 UI 内容,而不是当前应用程序的 UI 内容)。
  • 仅仅因为一些以 UI 为中心的代码需要作为视图之间的共性被分解出来,这并不意味着它得到了 VIPER 处理闯入其他 4 个区域 {interactor、presenter、entities、router} 的方式来表达共性。视区本身可以有图层。一个这样的层是两个或多个视图之间的通用基础设施库。(另一个这样的层可能是一个外观,它将以 UI 为中心的事件转换为以应用程序域为中心的事件,这些事件在区域间传递给演示者来处理,而不是作为以 UI 为中心的事件,而是作为一个应用程序域事件,与它的方式无关表示在 UI 中。)如果某些函数、方法、过程、子例程或协程需要作为视图区域内多个视图之间的共性分解出来,则保留该分解出的函数、方法、过程、子例程,
于 2021-04-23T15:30:51.950 回答