我需要将标题中的背景颜色设置为透明,但不设置为透明,我在MAPKit中使用自定义对话框引脚。什么是错的?
Backgroud View颜色设置为CLear Color ..
并以编程方式将颜色设置为“清除颜色”:
customMarkerXIB.backgroundColor = UIColor.clearColor()
import UIKit
@IBDesignable class Widget: UIView {
var view: UIView!
var nibName: String = "Widget"
@IBOutlet weak var titleLabel: UILabel!
/* @IBInspectable var image: UIImage? {
get {
return imageView.image
}
set(image) {
imageView.image = image
}
}
*/
@IBInspectable var title: String? {
get {
return titleLabel.text
}
set(title) {
titleLabel.text = title
}
}
func setSelectedState(){
println("hola")
}
// init
override init(frame: CGRect) {
// properties
super.init(frame: frame)
// Set anything that uses the view or visible bounds
setup()
}
required init(coder aDecoder: NSCoder) {
// properties
super.init(coder: aDecoder)
// Setup
setup()
}
func setup() {
view = loadViewFromNib()
view.frame = bounds
view.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
addSubview(view)
}
func loadViewFromNib() -> UIView {
let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: nibName, bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as UIView
return view
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
}
*/
}
加载自定义注释
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
var identifier = "CustomAnnotation"
var position = 0;
if let mapPin = annotation as? MyAnnotation {
position = mapPin.position; // assosiate annotation with a position
}
if annotation.isKindOfClass(MyAnnotation) {
var marker = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
if marker == nil {
marker = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
marker.tag = position;
marker.image = UIImage(named: "mapa_pin")
marker.centerOffset = CGPointMake(0, -10)
marker.canShowCallout = true
marker.backgroundColor = UIColor.clearColor()
//var pointTitle = marker!.annotation.title! as String
/* var label:UILabel = UILabel(frame: CGRectMake(0, CGFloat(floorf((56.0-20)/2)), 26.0, 20))
label.backgroundColor = UIColor.clearColor()
label.text = "asdfasdfasdfasd"
label.textAlignment = NSTextAlignment.Center
label.font = UIFont.systemFontOfSize(11.0)
marker.addSubview(label) */
var customMarkerXIB : Widget = Widget(frame: CGRect(x: 0, y: 250, width: 300, height: 150))
customMarkerXIB.backgroundColor = UIColor.clearColor()
customMarkerXIB.title = "olakease";
customMarkerXIB.setSelectedState()
marker.rightCalloutAccessoryView = customMarkerXIB
// Callout
/* var button = UIButton.buttonWithType(.DetailDisclosure) as UIButton
marker!.leftCalloutAccessoryView = button
var image = UIImageView(image: UIImage(named: "mapa_pin"))
marker!.rightCalloutAccessoryView = image*/
} else {
marker!.annotation = annotation
}
return marker
}