UIButton保存选中按钮

//纠结了四个小时的按钮 终于出来了,实现效果是保存选中按钮 实现数据传递,

//彩种按钮

NSMutableArray *showLabelArray = [NSMutableArray arrayWithCapacity:10];

[showLabelArray addObject:@"2串1"];//0

[showLabelArray addObject:@"3串1"];//2

[showLabelArray addObject:@"4串1"];//9

[showLabelArray addObject:@"5串1"];//1

[showLabelArray addObject:@"6串1"];//5

[showLabelArray addObject:@"7串1"];//8

[showLabelArray addObject:@"8串1"];

//添加彩种按钮

UIButton *btn = nil;

for (int i= 0; i<2; i++) {

for (int j = 0; j<4; j++) {

if (i == 1&&j==3) {

break;

}

btn = [UIButton buttonWithType:UIButtonTypeCustom];

[btn setTitle:[showLabelArray objectAtIndex:i*4+j] forState:UIControlStateNormal];

[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

btn.layer.borderColor = [UIColor lightGrayColor].CGColor;

btn.layer.borderWidth = 0.7;

btn.showsTouchWhenHighlighted = YES;

[btn addTarget:self action:@selector(chooseLottery:) forControlEvents:UIControlEventTouchUpInside];

btn.frame = CGRectMake(10+j*80, 50+i*40, 60, 30);

btn.tag =10+ i*4+j;

[button setBackgroundImage:[UIImage imageNamed:@"leagueBtn"] forState:UIControlStateNormal];

[chooseBackroundView addSubview:btn];

NSLog(@"btn.tag is %d",btn.tag);

}

}

-(void)chooseLottery:(UIButton *)sender{

UIButton *button = (UIButton *)sender;

for (int i=
0; i<2; i++) {

for (int j =
0; j<4; j++) {

if (i == 1&&j==3) {

break;

button = (UIButton *)[self.view
viewWithTag:i*4+j];

}

}

}

if (button.selected ==
YES)

{

button.selected = !button.selected;

[button setBackgroundImage:[UIImage
imageNamed:@"leagueBtn"]
forState:UIControlStateNormal];

NSString *tag1 = [NSString
stringWithFormat:@"%d", button.tag];

[array
removeObject:tag1];

}

else if (button.selected ==
NO)

{

button.selected = !button.selected;

[button setBackgroundImage:[UIImage
imageNamed:@"leagueBtn_selected"]
forState:UIControlStateNormal];

NSString *tag1 = [NSString
stringWithFormat:@"%d", button.tag];

[array
addObject:tag1];

}

for (int i =
0; i<[array
count]; i++) {

NSString *str = [array
objectAtIndex:i];

NSLog(@"保存按钮数组相对应的tag %@",str);

}

时间: 2024-10-29 21:49:06

UIButton保存选中按钮的相关文章

tabbar选中按钮的标题颜色和字体

@implementation XMGTabBarController /* 问题: 1.选中按钮的图片被渲染 -> iOS7之后默认tabBar上按钮图片都会被渲染 1.修改图片 2.通过代码 √ 2.选中按钮的标题颜色:黑色 标题字体大 -> 对应子控制器的tabBarItem 3.发布按钮显示不出来 */ // 只会调用一次 + (void)load { // 获取哪个类中UITabBarItem,appearance:只能在控件显示之前设置,才有作用 UITabBarItem *ite

Sharepoint2013 列表的NewForm 页面添加一个 保存新建 按钮

昨天一同事问我如何在sharepoint2013的NewForm.aspx页面上添加一个 save and new的button.实现save 和new的功能,save的功能和默认的save按钮效果一至. 效果如图: 这里的思路如下: 1)用juqery来动态添加一个saveandnew的button 2)新建按钮的click事件将要调用默认save 按钮的click方法 3)新按钮的click事件后页面跳转主要取决于url的Source参数,所以我们必须改写获取该参数的方法,该参数的读取是在i

选中按钮改变文字大小和颜色

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC" } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC"; min-height: 25.0px } p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #cf8724 }

实现选中的按钮与未选中按钮的交换,3步曲

三部曲; // 1.让当前选中的按钮取消选中 UIButton *selectedButton; self.selectedButton.selected = NO; // 2.让新点击的按钮选中 button.selected = YES; // 3.新点击的按钮就成为了"当前选中的按钮" self.selectedButton = button;

angularjs 水平滚动选中按钮高亮显示 swiper和回到顶部指令的实现ionic

首先安装 swiper npm install --save swiper 或者 bower install --save swiper <link rel="stylesheet" href="../bower_components/swiper/dist/css/swiper.min.css" /> <script src="../bower_components/swiper/dist/js/swiper.jquery.min.js

iOS Uibutton防止多按钮同时按下

今天在逛博客的时候偶然发现了这个问题,就是一个view上面有多个button可以用多个手指去 同时去点击button这个时候就会出现一些奇怪的问题 当然解决办法也很是简单 只要我们对每一个创建的btn都添加一句代码就可以了 //防止多个按钮同时被多个手指点击 [btn setExclusiveTouch:YES];

导航栏使用UIButton自定义返回按钮的图片

- (void)viewDidLoad { UIButton *backItem = [UIButton buttonWithType:UIButtonTypeCustom]; UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:backItem]; backItem.frame = CGRectMake(18, 5, 20, 20); [backItem setImage:[UIImage imageNamed

easyUI的datagrid 分页保存选中状态

<span style="font-size:18px;">onLoadSuccess:function(data){ var rows = data.rows; //从编辑页面传过来的指标编码 var indeCodes=$("#indeCodes").val(); var n=indeCodes.split(';').length-1; for(var i=0;i<rows.length;i++){ var obj = rows[i]; //循

elementUITable的多选框:分页选择数据回显,分页保存选中的数据。

<template> <el-table @selection-change="handleSelectionChange" :row-key="getRowKeys"> <!--type必须是selection的一列设置reserve-selection属性--> <el-table-column type="selection" :reserve-selection="true"