- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
嗨,我创建了我的自定义 marker.iconview
marker.iconView = CustomMarkerView(frame: CGRect(x: 0, y: 0, width: 301, height: 36))
这是我的自定义标记 View
import UIKit
class CustomMarkerView: UIView {
var logo = UIImage()
var adress = UILabel()
var price = UILabel()
var icon_like = UIImage(named: "icon_like")
var icon_direction = UIImage(named: "icon_direction")
override init(frame: CGRect) {
super.init(frame: frame)
self.addCustomView()
}
init(frame: CGRect, adress: String, price: String, logo: String) {
super.init(frame: frame)
self.adress.text = adress
self.price.text = price
self.logo = UIImage(named: logo)!
self.addCustomView()
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func addCustomView() {
let layerBG = CALayer()
layerBG.frame.size.width = 201
layerBG.frame.size.height = 36
layerBG.backgroundColor = UIColor(patternImage: UIImage(named: "bgMarkerView")!).cgColor
layerBG.position = CGPoint(x: 201, y: 18)
self.layer.addSublayer(layerBG)
}
然后我在我的 View Controller 中的这个 View 中添加更多自定义元素
func addInternalElements(adress: String, price: String, logo: String) {
let logoView = UIView()
let logoImg = UIImage(named: logo)
let logoImage = UIImageView(image: logoImg)
logoView.addSubview(logoImage)
setMarkerLogoConstraint(logoView: logoView, logoImage: logoImage)
let adressLabel = UILabel()
adressLabel.font = UIFont(name: "helveticaneuecyr-roman", size: 9)!
adressLabel.textColor = UIColor.white
adressLabel.numberOfLines = 2
adressLabel.text = adress
let priceLabel = UILabel()
priceLabel.font = UIFont(name: "helveticaneuecyr-roman", size: 11.2)!
priceLabel.textColor = UIColor.white
priceLabel.numberOfLines = 2
priceLabel.text = price
let icon_like = UIImage(named: "icon_like")
let likeBtn = UIButton()
likeBtn.setImage(icon_like, for: .normal)
likeBtn.setImage(icon_like, for: .selected)
likeBtn.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
likeBtn.tag = 5
likeBtn.isMultipleTouchEnabled = true
self.topBarView.addSubview(btnProfileTopBar)
setProfileIconConstraints()
self.marker.iconView?.addSubview(logoView)
self.marker.iconView?.addSubview(adressLabel)
self.marker.iconView?.addSubview(priceLabel)
self.marker.iconView?.addSubview(likeBtn)
self.marker.iconView?.isMultipleTouchEnabled = true
setLogoViewMarkerConstraints(logoView: logoView)
setAdressMarkerConstraints(label: adressLabel, logoView: logoView)
setPriceMarkerConstraints(label: priceLabel, logoView: logoView)
setLikeBtnMarkerConstraints(btn: likeBtn)
}
一切看起来都不错,但 uibutton 不可点击(likeBtn.addTarget 不起作用),如果我实现此方法
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
return false
}
我不明白我怎么理解我点击了正确的按钮(会有更多的按钮)
最佳答案
我已经解决了这个问题,在 infoWindow 中创建了自定义图标 View
关于ios - marker.iconView?.addSubview(UIButton) 无法使用 Gmaps 点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43867287/
我已经用 swift 编写了一堆代码并且更喜欢以编程方式编写很多代码,我想知道这两者之间的区别是什么: self.view.addSubview(someNewView) view.addSubvie
我在 tableviewcell 中有按钮。[cell addSubview:button] 和 [cell.contentview addsubview:button] 有什么区别?因为当我在 ta
我知道Apple建议开发者在self.contentview中添加 subview ,但是如果我们在UITableViewCell中添加 subview 会发生什么? 最佳答案 ios 7以后[s
我需要在 viewcontroller 的顶部显示 loaderView let loaderView: UIView() self.view.window?.addSubview(loaderVie
// Create and add a sub view CGRect viewRect = CGRectMake(0, 0, 200, 200); UIView *a_sub_view = [[UI
如何将 View 添加到窗口,以便调整 View 大小以适合窗口框架? 问题 我正在制作一个包含 2 个 View 的工作表窗口,其中一次只能看到其中一个 View ,因此 View 与窗口的大小相同
当我使用 addSubview方法,然后 removeFromSubview加载下一个 ViewController 然后加载 View 几次后,我的应用程序崩溃。我有很多关于 View 的图像。 尽
我试图让我的标 checkout 现动画: - (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer { if (isS
我有两个 UIView,名为 A 和 B,我将 UIView B 添加到 A 的 subview 中: [A.view addSubview B] 我想知道是否有任何委托(delegate)或 Hoo
我有类似的东西: (1) NavigationController --> (2) UITableViewController --> (3 afted clicked in a cell) UIVi
我有动画打开 NSViewController,它尝试添加 subview : [self.view addSubview:joinToCompanyView]; joinToCompanyView.
在使用 addSubview 时防止内存泄漏的正确方法是什么?我收到来自 Instruments 的投诉,说这段代码存在漏洞。我做错了什么? 示例代码: 我的.h @interface MyCusto
以下代码的结果是:我没有看到标签。 我的理解是标签的 intrinsicSize 会允许标签拉伸(stretch)。为什么没有发生这种情况? import UIKit class ViewContro
错误 -> “UIVIew”没有名为“addSubView”的成员 override func viewDidLoad() { super.viewDidLoad() // Do an
在使用 addSubview() 加载 View Controller View 时,我遇到了一个奇怪的行为: 硬件和软件:OSX 10.9.5 Mavericks、XCode 6 Beta 6 上的
使用 addSubview 方法向 UIAlertView 添加一些控件在 iOS7 中已弃用。据我所知,Apple promise 添加 contentView 属性。 iOS 7 现在发布了,我看
我有一个已加载到 MainWindow.xib 中的 View 。它只是一个带有 uiimageview 的 View ,在整个屏幕(320 X 480)上显示图像。当应用程序加载时,我显示此 Vie
我有一个基于 UITabBar 的应用程序,它运行得很好。在某些情况下,我会显示不同的 UIViewController。现在让我烦恼的是,我必须调整测试 Nib 的框架(并且仅测试 Nib !)才能
嗨,我正在 xcode 3.2.3 中编写一个应用程序。我想要做的就是切换到另一个 View ,但我不确定这样做的最佳方法。我可以通过这两种方式中的任何一种... PreferencesViewCon
我遇到了一个奇怪的问题..我想向我当前的 View 添加一个 UIViewcontroller(称为 iView)。我通过调用 iView = [[KFKaraokeInfosView allo
我是一名优秀的程序员,十分优秀!