我已经以编程方式在xcode中添加了按钮,但是当我通过模拟器运行它时,它没有动画,即它不像通常那样闪烁?
这是我添加按钮的方式:
closeButton = [[UIButton alloc] init];
closeButton.frame = CGRectMake(505, 5, 20, 20);
[closeButton setImage:imgBtn forState:UIControlStateNormal];
[closeButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[closeButton addTarget:self action:@selector(closeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:closeButton];
答案 0 :(得分:1)
您可以添加此内容以查看触摸事件
closeButton.showsTouchWhenHighlighted = YES;
或者您必须使用按钮类型UIButtonTypeRoundedRect
来查看按下按钮效果。
答案 1 :(得分:1)
试试这个
closeButton = [[UIButton alloc] init];
closeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]
closeButton.frame = CGRectMake(505, 5, 20, 20);
[closeButton setImage:imgBtn forState:UIControlStateNormal];
[closeButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[closeButton addTarget:self action:@selector(closeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:closeButton];