展现效果例如以下:


功能说明:
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="">

ios Button的更多相关文章

  1. iOS Button按钮 热区的放大

      Apple的iOS人机交互设计指南中指出,按钮点击热区应不小于44x44pt,否则这个按钮就会让用户觉得“很难用”,因为明明点击上去了,却没有任何响应. 但我们有时做自定义Button的时候,设计 ...

  2. ios button标记

    在写项目的时候,for循环创建多个button,在需要设置背景图片和,需要标记所选中的button的需求, 在这里提供两种方法: 一: 1:把for循环创建的button全部装到一个新建的数组中,把他 ...

  3. iOS button 里边的 字体的 摆放

    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; button.titleEdgeInsets ...

  4. iOS Button 上文字图片位置的设置

    1. 添加图片+文字/文字+图片 ,不分前后,图片默认在文字前边 加空格隔开 UIButton * button =[[UIButton alloc] initWithFrame:CGRectMake ...

  5. iOS Button选中与取消

    /** * 是否点击 */ @property (nonatomic ,assign) BOOL selected; /** *  button 点击事件选中取消选中 */ - (void)handl ...

  6. iOS button文字居中

    新建一个UIButton的category .h @interface UIButton (QXTitleInCenter) -(instancetype)init; @end .m @impleme ...

  7. iOS Button添加阴影 和 圆角

    用iamgeview 加手势代替 self.headimageview = [[UIImageView alloc] initWithFrame:CGRectMake(IPHONEWIDTH(13), ...

  8. iOS Button设置

    UIButton *kefuBtn = [[UIButton alloc]initWithFrame:CGRectMake(, , , )]; kefuBtn.backgroundColor = SX ...

  9. CSS3与页面布局学习总结(二)——Box Model、边距折叠、内联与块标签、CSSReset

    一.盒子模型(Box Model) 盒子模型也有人称为框模型,HTML中的多数元素都会在浏览器中生成一个矩形的区域,每个区域包含四个组成部分,从外向内依次是:外边距(Margin).边框(Border ...

随机推荐

  1. python 编写的经纬度坐标转换类

    # -*- coding: utf-8 -*- # /** # * 各地图API坐标系统比较与转换; # * WGS84坐标系:即地球坐标系,国际上通用的坐标系.设备一般包含GPS芯片或者北斗芯片获取 ...

  2. C#缓存

    最近在学习缓存的知识,博客园中的 缓存资料 觉得信息不错值得学习

  3. MVC学习日记(三)EntityFramework

    其实学会了第一篇的创建和第二篇的使用以后,基本的mvc操作足够了,至于验证神马的,还不如用Jquery.h5的好看适用,所以接下来, 后续上会讲一些比较实用的. 在之前的文章说到了基础的使用, 那么, ...

  4. Svn install and use

    1.安装服务 使用yum安装subversion,简单.不繁琐. 1 yum install -y subversion 2.创建版本库 1 2       mkidr /svn/obj        ...

  5. lua环境变量

    function foo() print(g or "'g' is not defined!") end foo() env = { g = 100, print = print ...

  6. 利用JavaScript实现文本框改文字功能

    <html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...

  7. size_t与size_type的使用

    size_t 是为了方便系统之间的移植而定义的 在32位系统上 定义为 unsigned int在64位系统上 定义为 unsigned long 更准确地说法是 在 32位系统上是32位无符号整形在 ...

  8. 用python(2.7)自定义实现SQL的集合操作

    有的时候需要在不同的数据库实例之间做集合操作,这就无法直接使用SQL语句的join,left join了.相同类型的数据库之间虽然也有类似于DBLINK和FEDERATED之类的东西,但一来这些东西不 ...

  9. 利用chrome浏览器断电调试确定函数触发的位置

    比如某天遇到这样一个问题,页面有一个按钮,上面绑定了事件可能是多个事件,然后我们点击后出现了bug,我们要如何快速定位到这个事件,如果页面只有一个js或少量的js,我们一个打开查找,也可以接受.但是如 ...

  10. 日常记录-Pandas Cookbook

    Cookbook 1.更新内容 2.关于安装 3.Pandas使用注意事项 4.包环境 5.10分钟Pandas初识 6.教程 7.Cookbook 8.数据结构简介 9.基本功能 10.使用文本数据 ...