我正在尝试在主视图上创建一个子视图。
添加 Web 视图和此子视图的退出按钮。
我通过创建一个圆圈和一个标签来通过视图创建退出按钮图像。
在我的代码下方,我的按钮操作(即退出按钮的功能)不执行。
这有什么问题?
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.frame = CGRectMake(0, 0, 1024, 768);
[self setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.8]];
UIView *circleView = [[UIView alloc] initWithFrame:CGRectMake(8,20,40,40)];
circleView.alpha = 0.5;
circleView.layer.cornerRadius = 20;
//self.circleView.backgroundColor = [UIColor blueColor];
circleView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
circleView.layer.borderColor = [[UIColor blackColor] CGColor];
circleView.layer.borderWidth = 5;
UILabel* circleIndex = [[UILabel alloc] init];
circleIndex.frame = CGRectMake(13, 10, 25, 20);
[circleIndex setFont:[UIFont fontWithName:@"Arial-BoldMT" size:22]];
[circleIndex setText:@"x"];
[circleView addSubview:circleIndex];
UIView *alertView = [[UIView alloc]initWithFrame:CGRectMake(40, 80, 944, 600)];
UIWebView* webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 944, 600)];
NSString *url=@"http://www.google.com";
NSURL *nsurl=[NSURL URLWithString:url];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webView loadRequest:nsrequest];
[alertView addSubview:webView];
UIButton *exit = [[UIButton alloc]init];
exit.frame = CGRectMake(920, -40, 38, 38);
[exit addTarget:self action:@selector(exitTheWebView) forControlEvents:(UIControlEventTouchUpInside)];
[exit addTarget:self action:@selector(exitTheAlert) forControlEvents:(UIControlEventTouchUpInside)];
[exit setBackgroundColor:[UIColor redColor]];
// exit setBackgroundImage:<#(UIImage *)#> forState:<#(UIControlState)#>
[circleView addSubview:exit];
[alertView addSubview:circleView];
[self addSubview:alertView];
}
return self;
}
-(void)exitTheWebView{
[self removeFromSuperview];
NSLog(@"bitch");
[self release];
}