2011-01-24 15 views
5

मैं एक MapView है, और मैं इसे एक dropshadow जोड़ना चाहते हैं, लेकिन विधि मैंने कोशिश काम नहीं करता है के लिए छाया जोड़ना:MKMapView

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    mapView.layer.shadowColor = [[UIColor blackColor] CGColor]; 
    mapView.layer.shadowOffset = CGSizeMake(10.0f, 10.0f); 
    mapView.layer.shadowOpacity = 1.0f; 
    mapView.layer.shadowRadius = 10.0f; 
} 

मैं इस मिल:

example

क्या मैं कुछ गलत कर रहा हूं?

उत्तर

9

हल करने के लिए धन्यवाद: http://blog.amarkulo.com/create-rounded-uiviews-with-shadow

इस कोड का उपयोग: एक UIView में MKMapView संलग्न करने

[[mapView layer] setMasksToBounds:NO]; 
[[mapView layer] setShadowColor:[UIColor blackColor].CGColor]; 
[[mapView layer] setShadowOpacity:1.0f]; 
[[mapView layer] setShadowRadius:6.0f]; 
[[mapView layer] setShadowOffset:CGSizeMake(0, 3)]; 
2

एक अन्य विकल्प (वास्तव में प्रस्तावित समाधान मेरे लिए काम नहीं किया, iOS SDK 4.3) है :

_mapContainer = [[UIView alloc] initWithFrame: CGRectMake (0.0f, 44.0f, 320.0f, container.frame.size.height - 44.0f)]; 
_mapContainer.autoresizingMask = UIViewAutoresizingFlexibleHeight; 
_mapContainer.layer.masksToBounds = NO; 
_mapContainer.layer.shadowColor = [UIColor blackColor].CGColor; 
_mapContainer.layer.shadowOffset = CGSizeMake (0.0f, 10.0f); 
_mapContainer.layer.shadowOpacity = 0.6f; 
_mapContainer.layer.shadowRadius = 5.0f; 
[container addSubview: _mapContainer]; 
[_mapContainer release]; 

_mapView = [[MKMapView alloc] initWithFrame: _mapContainer.bounds]; 
_mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight; 
[_mapContainer addSubview: _mapView]; 
[_mapView release]; 

इस तरह आप भी _mapContainer के फ्रेम चेतन कर सकते हैं और अभी भी अपनी सही जगह में छाया रखने के लिए।

यहां आप वास्तविक परिणाम here देख सकते हैं, यदि आप एक पंजीकृत ऐप्पल डेवलपर हैं।