好吧,我已经做了一百万次这种事情,但这个特殊情况让我无法理解,我敢肯定它只是我想念的一些愚蠢的事情......
但我试图在 mapView 上显示一个 UIView,以给人一种 mapview 被“禁用”的印象。
我创建了一个 UIView 子类并添加了一个标签。像这样...
。H
#import <UIKit/UIKit.h>
@interface DisabledOverlayView : UIView
@property (nonatomic, strong) UILabel *disabledOverlayViewText;
@end
没什么复杂的...
在我的 .m 中,我设置了文本并将其添加到我的 UIView 中。
@synthesize disabledOverlayViewText = _disabledOverlayViewText;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor blackColor];
self.alpha = 1;
_disabledOverlayViewText.textColor = [UIColor whiteColor];
_disabledOverlayViewText.frame = CGRectMake(0, 0, 200, 200);
// [_disabledOverlayViewText setCenter:self.center];
_disabledOverlayViewText.text = @"testing";
[self addSubview:_disabledOverlayViewText];
}
return self;
}
然后我希望使用这个覆盖的类我称之为......
DisabledOverlayView *disabledView = [[DisabledOverlayView alloc] initWithFrame:CGRectMake(12, 12, _mapView.frame.size.width, _mapView.frame.size.height)];
disabledView.disabledOverlayViewText.text = @"No Location";
[self.view addSubview:disabledView];
这些都不是太复杂..但标签没有出现。覆盖看起来很好,但没有标签文本。我弄乱了标签的框架,认为它可能不在可见视图中,但没有骰子。我无法弄清楚发生了什么。