Ⅰ 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,主要是為了添加點擊事件時可以正確的知道是那個按鈕觸發的。