admin管理员组文章数量:1023764
I am trying to create a custom iconView using SwiftUI for may Google Maps markers:
struct CustumMarkerView: View {
let inter15_500 = Font.inter(size: 15, weight: 500)
let destination: POILocation
var iconName: String {
switch destination.locationType.id {
case 1:
return "airplane"
case 2:
return "bus"
case 3:
return "train.side.front.car"
case 4:
return "building.2"
default:
return "party.popper"
}
}
var body: some View {
HStack(alignment: .center, spacing: 4) {
Text(destination.name)
.font(inter15_500)
.foregroundStyle(Theme.Color.black2)
.lineLimit(1)
Image(systemName: iconName)
.resizable()
.renderingMode(.template)
.aspectRatio(contentMode: .fit)
.padding(8)
.frame(width: 32, height: 32)
.background(Theme.Color.black6)
.foregroundStyle(.white)
.clipShape(.circle)
}
.frame(height: 32)
}
}
@MainActor
class CustomMarker: GMSMarker {
let destination: POILocation
init(destination: POILocation) {
self.destination = destination
super.init()
let swiftUIView = UIHostingController(rootView: CustumMarkerView(destination: destination)).view!
swiftUIView.translatesAutoresizingMaskIntoConstraints = false
swiftUIView.backgroundColor = .green
//swiftUIView.heightAnchor.constraint(equalToConstant: 32).isActive = true
self.iconView = swiftUIView
self.appearAnimation = .fadeIn
self.position = .init(
latitude: Double(destination.coordinate.latitude) ?? 0,
longitude: Double(destination.coordinate.longitude) ?? 0
)
}
}
If I don't add a height constraint it becomes like this:
If I add a height constraint it becomes like this:
Can anyone help me fix it?
I am trying to create a custom iconView using SwiftUI for may Google Maps markers:
struct CustumMarkerView: View {
let inter15_500 = Font.inter(size: 15, weight: 500)
let destination: POILocation
var iconName: String {
switch destination.locationType.id {
case 1:
return "airplane"
case 2:
return "bus"
case 3:
return "train.side.front.car"
case 4:
return "building.2"
default:
return "party.popper"
}
}
var body: some View {
HStack(alignment: .center, spacing: 4) {
Text(destination.name)
.font(inter15_500)
.foregroundStyle(Theme.Color.black2)
.lineLimit(1)
Image(systemName: iconName)
.resizable()
.renderingMode(.template)
.aspectRatio(contentMode: .fit)
.padding(8)
.frame(width: 32, height: 32)
.background(Theme.Color.black6)
.foregroundStyle(.white)
.clipShape(.circle)
}
.frame(height: 32)
}
}
@MainActor
class CustomMarker: GMSMarker {
let destination: POILocation
init(destination: POILocation) {
self.destination = destination
super.init()
let swiftUIView = UIHostingController(rootView: CustumMarkerView(destination: destination)).view!
swiftUIView.translatesAutoresizingMaskIntoConstraints = false
swiftUIView.backgroundColor = .green
//swiftUIView.heightAnchor.constraint(equalToConstant: 32).isActive = true
self.iconView = swiftUIView
self.appearAnimation = .fadeIn
self.position = .init(
latitude: Double(destination.coordinate.latitude) ?? 0,
longitude: Double(destination.coordinate.longitude) ?? 0
)
}
}
If I don't add a height constraint it becomes like this:
If I add a height constraint it becomes like this:
Can anyone help me fix it?
本文标签: Google Maps iOS SDK Custom marker iconView with SwiftUIStack Overflow
版权声明:本文标题:Google Maps iOS SDK: Custom marker iconView with SwiftUI - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745604269a2158637.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论