Ⅰ xcode5,ios开发,请问360安全市场搜索功能,点击空白处后生成一大堆热词按钮怎么实现
思路:
1、显然这些热词是从一堆热词中随机筛选出来的。这个步骤中就涉及到随机算法的知识。
你可以从这一堆热词hots(NSArray类型)中,随机出它的索引位置,再根据索引去找对象
-(void)getRandomData{
NSArray*hots=@[@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z"];
NSMutableSet*set=[[NSMutableSetalloc]initWithCapacity:0];
while(set.count<15){
intindex=arc4random()%(hots.count);
[setaddObject:hots[index]];
}
NSLog(@"set:%@",set);
}
2、第一步中拿到了随机得到的15个热词,接下来就是创建按钮了
-(void)createButton{
intposY=20;
NSArray*allObjs=[setallObjects];
for(inti=0;i<allObjs.count;i++){
intposX=arc4random()%300;
UIButton*btn=[UIButtonbuttonWithType:UIButtonTypeCustom];
btn.tag=i;
[btnsetTitle:allObjs[i]forState:UIControlStateNormal];
[btnsetFrame:CGRectMake(posX,posY,60,20)];/////width需要根据文本的长度做自动变化处理,这里高度固定为20px
[btnaddTarget:selfaction:@selector(btnPressed:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:btn];
posY+=btn.frame.size.height+5;/////updateposY
}
}
3、动画处理的思路
如果是缩放动画,这里你就可以使用CABasicAnimation了
/*放大缩小*/
//设定为缩放
CABasicAnimation*animation=[:@"transform.scale"];
//动画选项设定
animation.ration=2.5;//动画持续时间
animation.repeatCount=1;//重复次数
animation.autoreverses=YES;//动画结束时执行逆动画
//缩放倍数
animation.fromValue=[NSNumbernumberWithFloat:1.0];//开始时的倍率
animation.toValue=[NSNumbernumberWithFloat:2.0];//结束时的倍率
//添加动画
[myView.layeraddAnimation:animationforKey:@"scale-layer"];
Ⅱ iOS开发,UIButton怎样去掉高亮透明效果
首先,创建一个button类,然后,重写setHighlighted方法,里面不用写任何东西;
- (void)setHighlighted:(BOOL)highlighted{
}
Ⅲ iOS开发,用for创建6个按钮,摆成两行三列,代码该怎么写
for(int i=0; i<2; i++) {
for(int j=0; j<3; j++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(20+100*j, 40+150*i, 75, 122);
[btn setTitle:[NSString stringWithFormat:@"%d",(3*i+j)+1] forState:0];
btn.tag = 3*i+j;
[self.view addSubview:btn];
}
}
设置tag,主要是为了添加点击事件时可以正确的知道是那个按钮触发的。