【问题标题】:How to replicate UIKit/SwiftUI elements background (like the UITabBar/TabView background)如何复制 UIKit/SwiftUI 元素背景(如 UITabBar/TabView 背景)
【发布时间】:2020-04-26 14:26:41
【问题描述】:

我想复制 UITabBar(和类似的 UIKit/SwiftUI 元素)的背景(包括相同的模糊效果和细灰色边框及其适应性)并将其应用于另一个 UI 元素。 我怎样才能做到这一点?

我尝试复制它,但是当我将新视图堆叠在其他不同颜色的视图上时,行为会有所不同(并且不支持夜间模式)。

我不在乎答案是针对 UIKit 还是 SwiftUI 框架。

【问题讨论】:

    标签: swift uikit swiftui uinavigationbar uitabbar


    【解决方案1】:

    参见UIInterface 模块中的UIColor 扩展,如以下示例(那里有很多):

     * 1. systemBackground
     *    Use this stack for views with standard table views, and designs which have a white
     *    primary background in light mode.
     */
    @available(iOS 13.0, *)
    open class var systemBackground: UIColor { get }
    
    
    /* 2. systemGroupedBackground
     *    Use this stack for views with grouped content, such as grouped tables and
     *    platter-based designs. These are like grouped table views, but you may use these
     *    colors in places where a table view wouldn't make sense.
     */
    @available(iOS 13.0, *)
    open class var systemGroupedBackground: UIColor { get }
    
    
    /* Fill colors for UI elements.
     * These are meant to be used over the background colors, since their alpha component is less than 1.
     *
     * systemFillColor is appropriate for filling thin and small shapes.
     * Example: The track of a slider.
     */
    @available(iOS 13.0, *)
    open class var systemFill: UIColor { get }
    

    【讨论】:

    • 边框有这样的解决方案还是我必须手动制作?
    • @LorenzoFiamingo,我不想在答案中复制粘贴整个 UIInterface 模块 :)...UIColor.separatorUIColor.opaqueSeparator... 通读 UIInterface 那里有很好的描述。跨度>
    猜你喜欢
    • 1970-01-01
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    • 2020-11-20
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 2019-10-31
    相关资源
    最近更新 更多