首页 > 解决方案 > 按钮SwiftUi内图像的背景颜色问题

问题描述

按钮内的图像显示为蓝色。我不知道如何解决它。

Button(action: {self.count += 1}) {
    Circle()
        .fill(LinearGradient(gradient: Gradient(colors: [Color("linkAccount1"), Color("linkAccount2")]), startPoint: UnitPoint(x: 0, y: 0.2), endPoint: UnitPoint(x: 1, y: 1)))
        .frame(width: 80, height: 80)
        .shadow(color: Color("shadowColor1"), radius: 7, y: 7)
        .overlay(
            //issue with image backgroud or foregroundColor
            Image("linkAccount")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 60, height: 60))
}

解决方案:Image("linkAcount").renderingMode(.original)

标签: buttonswiftui

解决方案


按钮中包含的图像和文本以强调色呈现,默认情况下为蓝色,只需应用:

.accentColor(.white)

到您的 Button 以将图像绘制为白色。


推荐阅读