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 ...
随机推荐
- html转义字符换行以及回车等的使用
欢迎加入前端交流群交流知识&&获取视频资料:749539640 html换行回车转义字符 换行Line feed 回车Carriage Return html中换行转义字符 的使 ...
- String不可变性
今天分析一下String,String有很多实用的特性,比如说“不可变性”,是工程师精心设计的艺术品.用final就是拒绝继承,防止内部属性或方法被破坏. 一,什么是不可变? String不可变很简单 ...
- C# 添加应用程序包
项目中可能会遇到某些扩展方法不可以应用的情况,这时候需要在项目中引用程序包 步骤如下: 回车即可
- Android GoogleMap 谷歌地图从零开始
说明 由于国内使用v2最新的谷歌地图有很多限制,所有如果要在真机上测试运行要做一些准备 准备1: vpn必不可少啦 推荐cloud vpn或者betternet都是不错的免费vpn 准备2: 由于最新 ...
- 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 ...
- windows安装pyspider
基本环境 python2.7 win7 64bit 问题 Microsoft Visual C++ 10.0 is required Microsoft Visual C++ Compiler for ...
- RAID5存储上parted进行分期及UUID对应关系
#parted [设备] [命令 [参数]]命令功能: 新增分区:mkpart [primary|logical|extended] [ext3|vfat] 开始 结束 分区表:print 删除分区: ...
- Junit使用第二弹
实例总结 1. 参数化测试 有时一个测试方法,不同的参数值会产生不同的结果,那么我们为了测试全面,会把多个参数值都写出来并一一断言测试,这样有时难免费时费力,这是我们便可以采用参数化测试来解决这个问题 ...
- javascript中函数表达式的问题讨论
#函数表达式 ##函数声明和函数表达式的区别 函数的定义有两种形式,一种是函数声明,一种是函数表达式 使用声明时,要注意函数声明提升现象,比如说在if语句中使用声明会出错,但是表达式就不存在这个问题 ...
- Java中数组遍历
就是将数组中的每个元素分别获取出来,就是遍历.遍历也是数组操作中的基石. 数组的索引是 0 到 lenght-1 ,可以作为循环的条件出现 public class ArrayDemo4 { publ ...