如何在选择中突出显示自定义UIButton
约5秒,然后重定向到其他视图?在我的代码中,选择时不会显示任何颜色而是重定向到其他视图。
这是我的代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGRect rect=CGRectMake(0+70*j,yy,79,40);
UIButton *button=[[UIButton alloc] initWithFrame:rect];
[button setFrame:rect];
[button setContentMode:UIViewContentModeLeft];
button.titleLabel.font = [UIFont systemFontOfSize:14];
NSString *settitle=[NSString stringWithFormat:@"%@",item.TimeStart];
[button setTitle:settitle forState:UIControlStateNormal];
NSString *tagValue=[NSString stringWithFormat:@"%d%d",indexPath.section+1,i];
button.tag=[tagValue intValue];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setShowsTouchWhenHighlighted:YES];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside ];
[hlcell.contentView addSubview:button];
[button release];
}
-(IBAction)buttonPressed:(id)sender
{
[sender setBackgroundColor:[UIColor cyanColor]];
Login *lgn=[[Login alloc] init];
[self presentModalViewController:lgn animated:NO];
[lgn release];
}
我该怎么做?
答案 0 :(得分:0)
您必须将setShowsTouchWhenHighlighted:yes
设置为UIButton。
例如:
UIButton *click_btn=[UIButton buttonWithType:UIButtonTypeCustom];
click_btn.frame=CGRectMake(238,10, 70, 70);
[click_btn setTag:indexPath.row];
[click_btn setShowsTouchWhenHighlighted:YES];
[click_btn addTarget:self action:@selector(sample) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:click_btn];
答案 1 :(得分:0)
你只需在该方法中添加sleep(5);
例如:
这是用户示例uibutton操作方法。
- (无效)样品{
睡眠(5);
sampleclass * classobject = [[sampleclass alloc] init]; [self.navigationController pushViewController:classobject animated:YES];
}
答案 2 :(得分:0)
我不建议使用sleep(),因为这会睡眠所有线程并使应用程序基本上死了x秒。
按照上述说明突出显示按钮,然后使用
[self performSelector:@selector(sample) withObject:self afterDelay:5.0f];
-(void)sample
{
UIViewController *myNewController = [[UIViewController alloc]init];
enter code here
[self presentModalViewController:myNewController animated:YES];
}