用button 属性来保存字符串地址
我用到for循环创建button 通过点击不同的按钮拿到每个button对应的链接地址,因为button的个数也是通过后台数据返回。上代码:
//保存到数组
_array = [Article mj_objectArrayWithKeyValuesArray:dic[@"data"]];
//显示隐藏
BOOL show = dic[@"show"];
NSLog(@"%@",_array);
for (Article *article in self.array) {
_article = article;
CGFloat with = article.width;
CGFloat height = article.height;
//for循环创建button
for (int i=0; i<_array.count; i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tag = i;
[button setTitle:@"按钮" forState:UIControlStateNormal];
button.frame = CGRectMake(kSWidth-kSWidth*with, kSHeight - kSWidth*height*i-kSWidth*height-kTabBarHeight, kSWidth*with, kSWidth*height);
button.adjustsImageWhenHighlighted = NO;
[button sd_setImageWithURL:[NSURL URLWithString:[_array[i]imgUrl]] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor clearColor]];
[button addTarget:self action:@selector(resignButton:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:[_array[i]title] forState:UIControlStateNormal];
//用restorationIdentifier来记录每个button的url
button.restorationIdentifier = (NSString *)[_array[i] url];
// [button setRestorationIdentifier:[self.array[i]url]];
if (show==YES) {
button.hidden = NO;
}else{
button.hidden = YES;
}
[self.view addSubview:button];
}
}
//点击事件
- (void)resignButton:(UIButton *)sender{
// sender.highlighted = NO;
NSLog(@"%ld",sender.tag);
//字符串替换 赋值
NSString *informString = sender.restorationIdentifier;
//跳转操作就行了
}
用button 属性来保存字符串地址的更多相关文章
- 科学计算三维可视化---Traits(Event和button属性)
Event和button属性 是两个专门用于处理事件的change属性 Event属性和其他Trait属性不一样 Button属性是由Event属性继承而来的 Event监听 from traits. ...
- java保存json格式数据,保存字符串和读取字符串
1.java保存json格式数据,保存字符串和读取字符串 import java.io.*; class RWJson { public void wiite(String s, String toS ...
- 我的Android进阶之旅------>android Button上面的英文字符串自动大写的问题解决
今天碰到一个关于Button的问题:android Button上面的英文字符串会自动变成大写,运行的Android 5.1版本,如下图所示: 图1:Button 图2:TextView 这个Butt ...
- 我的Android进阶之旅------>android Button上面的英文字符串自己主动大写的问题解决
今天碰到一个关于Button的问题:android Button上面的英文字符串会自己主动变成大写,执行的Android 5.1版本号,例如以下图所看到的: 图1:Button 图2:TextView ...
- ext button 属性
var buttonName = new Ext.Button({ id:"buttonName", text:" ...
- C# 根据实体类的属性动态生成字符串
情景: 目前有两个实体类:Student,ClassInfo. public class Student { public string Name { get; set; } public strin ...
- 保存字符串到手机SDcard为txt文件
try { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File sdCardDir ...
- js操作对象属性值为字符串
今天在项目开发中遇到一个没遇到过的问题,这个问题是需要对比两个对象a和b,a是一个只有一个属性的对象,b是一个含有多个属性对象,如果b中包含和a一模一样的属性名和值,则把这个一样的属性和值从b中删除了 ...
- Android—修改button属性
一般安卓里的普通按钮控件灰灰的,比较单调,我们可以给按钮加上背景图片,或者自定义按钮的圆角,颜色等属性. 下面用代码举例: <Button android:id="@+id/reset ...
随机推荐
- 使用rpm安装指定版本的docker(1.12.6)
一.原因 如果系统是Centos7.3,直接使用yum install docker安装的docker版本是1.13.1,导致在创建容器的会报错,错误如下: 所以为了防止安装高版本的docker引发的 ...
- Simple Windows Service in C++
本文是来自CodeProject中的一篇名为Simple Windows Service in C++的译文,原文地址为:https://www.codeproject.com/Articles/49 ...
- turtle绘制图形
Example1: import turtle as t #初始设置画笔的宽度(size).颜色(color) t.pensize(5) t.pencolor("black") # ...
- Unable to load template file 'rj\ThinkPHP/Tpl/dispatch_jump.tpl'----thinkphp3.2.3
Unable to load template file 'rj\ThinkPHP/Tpl/dispatch_jump.tpl'----thinkphp3.2.3 1.报错原因:将thinkphp默认 ...
- (四十八)c#Winform自定义控件-下拉按钮
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- [python]打开文件操作open用法
1. 格式 handle = open(file_name, access_mode = 'r') file_name: 希望打开的文件名 access_mode: 'r'表示读取,'w'表示写入,' ...
- 2019NC#1
LINK B Integration 题意: 给定$a_1,a_2,...,a_n$, 计算 $$\frac{1}{π}\int_{0}^{\infty}\frac{1}{\prod\limits_{ ...
- UVA 11294 wedding 2-sat
可以把一对夫妇当成一个节点,然后拆点的话,h和w分别为真和假,然后直接按照题目中说的建图染色即可 #include <iostream> #include <cstdio> # ...
- codeforces 862 C. Mahmoud and Ehab and the xor(构造)
题目链接:http://codeforces.com/contest/862/problem/C 题解:一道简单的构造题,一般构造题差不多都考自己脑补,脑洞一开就过了 由于数据x只有1e5,但是要求是 ...
- 2018年全国多校算法寒假训练营练习比赛(第二场) B TaoTao要吃鸡 01背包变形题
链接:https://www.nowcoder.com/acm/contest/74/B来源:牛客网 Taotao的电脑带不动绝地求生,所以taotao只能去玩pc版的荒野行动了, 和绝地求生一样,游 ...