展现效果例如以下:


功能说明:
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,填充代码后例如以下

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

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

  1. - (IBAction)btnTouch:(id)sender {
  2. CGRect frame = CGRectMake(90, 100, 200, 60);
  3. UIButton *someAddButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  4. someAddButton.backgroundColor = [UIColor clearColor];
  5. [someAddButton setTitle:@"点击试试看!" forState:UIControlStateNormal];
  6. someAddButton.frame = frame;
  7. [someAddButton addTarget:self action:@selector(someButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  8. [self.view addSubview:someAddButton];
  9.  
  10. }

4 总体代码预览

  1. //
  2. // ViewController.m
  3. // btn_move
  4. //
  5. // Created by selfimprovement on 15-6-10.
  6. // Copyright (c) 2015年 sywaries@sina.cn. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10.  
  11. @interface ViewController ()
  12.  
  13. @end
  14.  
  15. @implementation ViewController
  16.  
  17. //监听方法
  18. -(void)someButtonClicked{
  19. // NSLog(@"点击成功!");
  20. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
  21. message:@"您点击了动态按钮。"
  22. delegate:self
  23. cancelButtonTitle:@"确定"
  24. otherButtonTitles:@"取消",@"点击index",nil];
  25. [alert show];
  26. }
  27.  
  28. //托付
  29. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  30. {
  31. NSLog(@"buttonIndex:%d", buttonIndex);
  32. }
  33.  
  34. //按钮action
  35. - (IBAction)btnTouch:(id)sender {
  36. CGRect frame = CGRectMake(90, 100, 200, 60);
  37. UIButton *someAddButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  38. someAddButton.backgroundColor = [UIColor clearColor];
  39. [someAddButton setTitle:@"点击试试看!" forState:UIControlStateNormal];
  40. someAddButton.frame = frame;
  41. [someAddButton addTarget:self action:@selector(someButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  42. [self.view addSubview:someAddButton];
  43.  
  44. }
  45.  
  46. //立刻载入百度,但是被背景覆盖
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 240, 360)];
  50. NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
  51. [self.view addSubview: webView];
  52. [webView loadRequest:request];
  53. // Do any additional setup after loading the view, typically from a nib.
  54. }
  55.  
  56. - (void)didReceiveMemoryWarning {
  57. [super didReceiveMemoryWarning];
  58. // Dispose of any resources that can be recreated.
  59. }
  60.  
  61. -(void)loadWebPageWithString:(NSString*)urlString{
  62. }
  63.  
  64. @end

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



UIAlertViewDelegate 就是加入托付

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

  1. //托付
  2. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  3. {
  4. NSLog(@"buttonIndex:%d", buttonIndex);
  5. }

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. html转义字符换行以及回车等的使用

    欢迎加入前端交流群交流知识&&获取视频资料:749539640 html换行回车转义字符 换行Line feed   回车Carriage Return  html中换行转义字符 的使 ...

  2. String不可变性

    今天分析一下String,String有很多实用的特性,比如说“不可变性”,是工程师精心设计的艺术品.用final就是拒绝继承,防止内部属性或方法被破坏. 一,什么是不可变? String不可变很简单 ...

  3. C# 添加应用程序包

    项目中可能会遇到某些扩展方法不可以应用的情况,这时候需要在项目中引用程序包 步骤如下: 回车即可

  4. Android GoogleMap 谷歌地图从零开始

    说明 由于国内使用v2最新的谷歌地图有很多限制,所有如果要在真机上测试运行要做一些准备 准备1: vpn必不可少啦 推荐cloud vpn或者betternet都是不错的免费vpn 准备2: 由于最新 ...

  5. MySQL 5.6 Reference Manual-14.7 InnoDB Table Compression

    14.7 InnoDB Table Compression 14.7.1 Overview of Table Compression 14.7.2 Enabling Compression for a ...

  6. windows安装pyspider

    基本环境 python2.7 win7 64bit 问题 Microsoft Visual C++ 10.0 is required Microsoft Visual C++ Compiler for ...

  7. RAID5存储上parted进行分期及UUID对应关系

    #parted [设备] [命令 [参数]]命令功能: 新增分区:mkpart [primary|logical|extended] [ext3|vfat] 开始 结束 分区表:print 删除分区: ...

  8. Junit使用第二弹

    实例总结 1. 参数化测试 有时一个测试方法,不同的参数值会产生不同的结果,那么我们为了测试全面,会把多个参数值都写出来并一一断言测试,这样有时难免费时费力,这是我们便可以采用参数化测试来解决这个问题 ...

  9. javascript中函数表达式的问题讨论

    #函数表达式 ##函数声明和函数表达式的区别 函数的定义有两种形式,一种是函数声明,一种是函数表达式 使用声明时,要注意函数声明提升现象,比如说在if语句中使用声明会出错,但是表达式就不存在这个问题 ...

  10. Java中数组遍历

    就是将数组中的每个元素分别获取出来,就是遍历.遍历也是数组操作中的基石. 数组的索引是 0 到 lenght-1 ,可以作为循环的条件出现 public class ArrayDemo4 { publ ...