1、在h文件中定义,第一个按钮对应-(IBAction) addButton:(id)sender; 并在m文件中实现它。
-(IBAction)addButton:(id)sender{
CGRect frame = CGRectMake(90, 200, 200, 60);
UIButton *someAddButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
someAddButton.backgroundColor = [UIColor clearColor];
[someAddButton setTitle:@"动态添加一个按钮!" forState:UIControlStateNormal];
someAddButton.frame = frame;
[someAddButton addTarget:self action:@selector(someButtonClicked)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:someAddButton];
}
这里还涉及到第二个方法someButtonClicked。
2、我们下面实现它
-(void) someButtonClicked{
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"提示"
message:@"您点击了动态按钮!"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:@"第二项", @"第三项", nil] autorelease];
[alert show];
}
以上两个方法实现对第一个按钮的监听,在第一个按钮被点击之后,动态生成第二个按钮; 如果在点击第二个按钮,则弹出提示信息框。
下面要实现对UIAlertView的监听。
3、首先要在h文件遵守协议<UIAlertViewDelegate>,具体代码是
@interface ViewController : UIViewController<UIAlertViewDelegate>
.........
@end
在m文件中实现alertView的若干方法,这里只实现一个方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@" button index=%d is clicked.....", buttonIndex);
}
相关推荐
因为iOS8 以后UIAlertView已经不推荐使用 所以自己简单封装了一下UIAlertView 和 UIAlertController 根据系统自动选择 封装的比较简单 为了方便使用而已
NULL 博文链接:https://ikrboy.iteye.com/blog/2002976
前两年IOS应用源码-主要是用于毕业设计学习的。
https://github.com/STShenZhaoliang/STAlertView 400行写的自定义UIAlertView,没有开太多接口,大家可以自由修改。
swift - UIAlertView的使用
简单的 UIAlert 封装 如果 (iOS )使用 UIAlertView 如果 (iOS >= 8) UIAlertViewController. 使用方法和示例 UIAlertCategory * a = [[UIAlertCategory alloc] initWithTitle:@"警告" WithMessage:@"你有条...
ios7 自定义UIAlertView ios7 UIAlertView 弹出 警告 自定义 简单实用。 支持转屏
1.系统的UIAlertView使用方便,但是有时需要三个按钮,这时的UIAlertView会出现问题,三个按钮的默认摆放位置,不尽人意 2.使用UIAlertView的Delegate,来修改其布局
NULL 博文链接:https://dingran.iteye.com/blog/1770376
自iOS7开始,addAlview在UIAlertView中不可用。 此类的视图层次结构是私有的,不能修改。 作为解决方案,此类创建一个iOS样式的对话框,您可以使用任何UIViews或按钮对其进行扩展。 动画和外观也被复制,不需要...
一个简单的封装UIalertView,可以达到展示列表的目的
自定义 UIAlertView
iOS程序中的Action Sheet就像Windows中的 “确定-取消”对话框一样,用于强制用户进行选择。当用户将要进行的操作具有一定危险时,常常使用Action Sheet对用户进行危险提示,这样,用户有机会进行取消操作。 Alert...
第二个私有类称为MyButton并保存每个添加按钮的信息。 UIAlert 类非常简单,并尝试仅涵盖UIAlertView基本功能。 UIAlertViewController更加灵活 - 例如参见 (仅在 Swift 中) 安装 只需将UIAlert/MyAlertMessage....
let alrtView = ChoiceAlrtView() @IBAction func OutLogin(_ sender: UIButton) { alrtView.showChoice(str: "确认退出吗") alrtView.resualtBlock = {(isTrue : Bool) in if isTrue { print("是") ...
简单的UIAlertView
imitate - UIAlertVIew you can add your customVIew 链接:https://github.com/YYXuelangwang/YYAlertView
自定义类似于UIAlertView
ios应用源码之仿uialertview和uiactionsheet的一个效果
IOS应用源码——仿UIAlertView和UIActionSheet的一个效果.zip