首先,设置一个视图弹出的触发事件,我用的是一个button点击事件
UIButton * button3 = [UIButton buttonWithType:UIButtonTypeCustom];
button3.frame = CGRectMake(22, 342, self.view.frame.size.width-44, 36);
[button3 setTitle:@"00:00" forState:UIControlStateNormal];
[button3 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[button3 addTarget:self action:@selector(showView) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button3];
然后写button的点击触发事件-(void)showView{
//设置弹出视图
UIView * view = [[UIView alloc]initWithFrame:CGRectMake(22, 400, 120, 222)];
view.backgroundColor = [UIColor redColor];
//实现弹出方法
UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
window.windowLevel = UIWindowLevelNormal;
[keywindow addSubview:view];
}
最后简单说一下,当你有了view以后可以随意定义任何控件了