Add text on custom marker on google map for ios

后端 未结 4 1278
青春惊慌失措
青春惊慌失措 2020-12-31 08:56

Am trying to put marker with Textview .Is there any posibility to add text over marker on google map in ios.

  • Like This

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 09:22

    func createImage(_ count: Int) -> UIImage? {
        let string = String(count)
        let paragraphStyle = NSMutableParagraphStyle()
        let font = UIFont.systemFont(ofSize: 9.5)
        paragraphStyle.alignment = .center
        let attributes: [NSAttributedString.Key: Any] = [
            .font : font,
            .foregroundColor: UIColor.black,
            .paragraphStyle: paragraphStyle
        ]
        
        let attrStr = NSAttributedString(string: string, attributes: attributes)
    
        let image = self.imageWithImage(image: UIImage(named: "pin_online.png")!, scaledToSize: CGSize(width: 50.0, height: 60.0))
        UIGraphicsBeginImageContext(image.size)
        UIGraphicsBeginImageContextWithOptions(image.size, false, 0.0)
        image.draw(in: CGRect(x: 0, y: 0, width: CGFloat(image.size.width), height: CGFloat(image.size.height)))
        let rect = CGRect(x: 14.7, y: CGFloat(3), width: CGFloat(image.size.width), height: CGFloat(image.size.height))
        attrStr.draw(in: rect)
        let markerImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
    
        return markerImage
    }
    

提交回复
热议问题