展现效果例如以下:


功能说明:
1加入来图片背景,
2动态展现百度网页,
3动态加入button。
4展现提示框。展现你点击提示框得index


 我成功来你也快来试试。







1 详细得项目创建与拖动button到storyboard 就不在详述

 

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDIzNjU1MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

 storyboard 上加入来button。同一时候也添加来背景。

2 按住ctrl键拖拽到ViewController.m文件空白处,生成someButtonClicked,填充代码后例如以下

-(void)someButtonClicked{
// NSLog(@"点击成功。");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"您点击了动态button!"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:@"取消",@"点击index",nil];
[alert show];
}

3 动态生成button 点击事件(提示框)

- (IBAction)btnTouch:(id)sender {
CGRect frame = CGRectMake(90, 100, 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]; }

4 总体代码预览

//
// ViewController.m
// btn_move
//
// Created by selfimprovement on 15-6-10.
// Copyright (c) 2015年 sywaries@sina.cn. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController //监听方法
-(void)someButtonClicked{
// NSLog(@"点击成功!");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
message:@"您点击了动态按钮。"
delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:@"取消",@"点击index",nil];
[alert show];
} //托付
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"buttonIndex:%d", buttonIndex);
} //按钮action
- (IBAction)btnTouch:(id)sender {
CGRect frame = CGRectMake(90, 100, 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]; } //立刻载入百度,但是被背景覆盖
- (void)viewDidLoad {
[super viewDidLoad];
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 240, 360)];
NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
[self.view addSubview: webView];
[webView loadRequest:request];
// Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} -(void)loadWebPageWithString:(NSString*)urlString{
} @end

5 为了知道你点击提示框得那一个index ,添加托付,和实现托付



UIAlertViewDelegate 就是加入托付

6 最后就是实现托付方法。目的就是知道您点击那一个index

//托付
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"buttonIndex:%d", buttonIndex);
}

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDIzNjU1MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">

最新文章

  1. HTML5的浏览器支持方案
  2. Java 之 异常处理
  3. 正则表达式之JSP、Android
  4. DIV+CSS实现左侧带三角形的提示框
  5. jQuery设计思想之取值和赋值
  6. html插入链接
  7. jq 幻灯片插件制作
  8. 基于LAMP平台的网站架构(或Web系统架构)
  9. 【转】HDMI控制与组态剖析
  10. 排序(4)---------希尔(shell)排序(C语言实现)
  11. testNg的安装与卸载
  12. 简单搭建SpringMVC框架详解
  13. 代理服务器 详解 Apache与Nginx的比较与分析
  14. Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'系列一:
  15. java-14习题
  16. ES6-你不知道的箭头函数
  17. java.io.Serializable 序列化问题【原】
  18. sitecore系统教程之使用修补程序文件自定义Sitecore配置
  19. jdk和二进制 常量.变量
  20. 【flex】学习笔记/总结

热门文章

  1. Python迭代与递归方法实现斐波拉契数列
  2. Super超级ERP系统---(8)订单管理--订单创建
  3. 数据库表结构导出sql语句
  4. 移动端rem设置(部分安卓机型不兼容)
  5. VueJS 开发常见问题集锦
  6. RN打包的那些坑儿
  7. [Shell] echo/输出 中引用命令
  8. VS Code中编写html(3) 标签的宽高颜色背景设置
  9. JS 20180415作业
  10. immutable-js基础