ios Button
展现效果例如以下:



1 详细得项目创建与拖动button到storyboard 就不在详述
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDIzNjU1MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
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的更多相关文章
- iOS Button按钮 热区的放大
Apple的iOS人机交互设计指南中指出,按钮点击热区应不小于44x44pt,否则这个按钮就会让用户觉得“很难用”,因为明明点击上去了,却没有任何响应. 但我们有时做自定义Button的时候,设计 ...
- ios button标记
在写项目的时候,for循环创建多个button,在需要设置背景图片和,需要标记所选中的button的需求, 在这里提供两种方法: 一: 1:把for循环创建的button全部装到一个新建的数组中,把他 ...
- iOS button 里边的 字体的 摆放
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; button.titleEdgeInsets ...
- iOS Button 上文字图片位置的设置
1. 添加图片+文字/文字+图片 ,不分前后,图片默认在文字前边 加空格隔开 UIButton * button =[[UIButton alloc] initWithFrame:CGRectMake ...
- iOS Button选中与取消
/** * 是否点击 */ @property (nonatomic ,assign) BOOL selected; /** * button 点击事件选中取消选中 */ - (void)handl ...
- iOS button文字居中
新建一个UIButton的category .h @interface UIButton (QXTitleInCenter) -(instancetype)init; @end .m @impleme ...
- iOS Button添加阴影 和 圆角
用iamgeview 加手势代替 self.headimageview = [[UIImageView alloc] initWithFrame:CGRectMake(IPHONEWIDTH(13), ...
- iOS Button设置
UIButton *kefuBtn = [[UIButton alloc]initWithFrame:CGRectMake(, , , )]; kefuBtn.backgroundColor = SX ...
- CSS3与页面布局学习总结(二)——Box Model、边距折叠、内联与块标签、CSSReset
一.盒子模型(Box Model) 盒子模型也有人称为框模型,HTML中的多数元素都会在浏览器中生成一个矩形的区域,每个区域包含四个组成部分,从外向内依次是:外边距(Margin).边框(Border ...
随机推荐
- ORA-03137 - ORA-12592 TNS:BAD PACKET OR ORA-3137 故障处理
环境 操作系统:CentOS release 6.8 数据库:oracle 11.2.0.4.190115 说明:数据库psu 为19年1月份的补丁,可不间断运行,但是开发提示在执行一些批处理的时候, ...
- golang iris下面的websocket
最近要做后台主动推送:(iris框架,封装的有wesocket,刚开始以为直接拿过来用,结果不是现在贴一下代码,写一下遇到的坑) func main() { app := iris.New() ...
- Selenium等待某个元素出现之隐式等待
找不到元素这个问题困扰了两天了,一直怀疑是页面div层次太多,定位不准确.于是就从table开始到最后一层精确定位,仍然找不元素.怎么办,在网上搜索答案,说是可以加个隐式试试,于是在执行前加了一句等待 ...
- Hadoop MapReduce编程 API入门系列之wordcount版本4(八)
这篇博客,给大家,体会不一样的版本编程. 是将map.combiner.shuffle.reduce等分开放一个.java里.则需要实现Tool. 代码 package zhouls.bigdata. ...
- Jquery 重置表单
1.重置表单回初始状态 $('#fromid')[0].reset(); 此方法一步到位,不需要一个个的去赋值为空
- JQuery学习笔记系列(二)----
jQuery是一个兼容多浏览器的javascript库,核心理念是write less,do more(写得更少,做得更多).其中也提供了很多函数来更加简洁的实现复杂的功能. 事件切换函数toggle ...
- nodejs supervisor安装
使用supervisor提高nodejs调试效率 用超级用户运行npm -g install supervisor命令,说是顺 >$ sudo npm -g install supervisor ...
- C# 递归产生树
//递归产生树 private void CreateTwo(TreeNode node, int id) { #region --根据指定ID查找数据到 dt string strSql = &qu ...
- 行间事件传this的问题:
在做1个简单功能的时候,行间事件这块发现了1个问题: <!doctype html> <html> <head> <meta charset="ut ...
- Python数据分析4------------数据变换
1.简单变换: 开方.平方.对数等 2.数据规范化: (1)离差标准化(最小最大标准化):消除量纲(单位)影响以及变异大小因素的影响. x1=(x-min)/(max-min) 代码:data1=(d ...