博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios Button
阅读量:6914 次
发布时间:2019-06-27

本文共 3266 字,大约阅读时间需要 10 分钟。

展现效果例如以下:

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

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

 
 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);}

你可能感兴趣的文章
常用的php函数库
查看>>
迭代器 生成器
查看>>
注解学习(模仿springMvc的注解注入方式)
查看>>
Oracle数据库常用监控语句
查看>>
git报错:src refspec master does not match any
查看>>
How to uninstall (remove) JAVA from OS X Lion
查看>>
hihoCoder1195 (高斯消元裸题)
查看>>
图片延迟加载并等比缩放,一个简单的JQuery插件
查看>>
用扩展开发一个PHP类
查看>>
使用Netty3或Netty4发布Http协议服务
查看>>
2011 聪明的质监员
查看>>
Redis之Set命令
查看>>
构建之法阅读笔记二。
查看>>
梦断代码阅读笔记一。
查看>>
【python】-- 多进程的基本语法 、进程间数据交互与共享、进程锁和进程池的使用...
查看>>
linux虚拟机使用VMware的NAT共享windows主机IP上网 [转]
查看>>
Rabbitmq编程
查看>>
C++虚函数
查看>>
Android记住密码后自动登录
查看>>
python 訪问webservice
查看>>