我希望能够在点击和拖动标签时更改标签的边框颜色,并且在没有点按和拖动时,边框颜色应该返回到之前的颜色。我已经使用了pan和tap手势识别器,但我不知道在编写代码来改变它。这是我的代码:
(void)change:(id)sender {
CGRect labelFrame = CGRectMake(230, 240, 300, 30);
UILabel *headingLabel = [[UILabel alloc] initWithFrame:labelFrame];
headingLabel.layer.borderColor = [UIColor clearColor].CGColor;
headingLabel.layer.borderWidth = 1.0;
headingLabel.backgroundColor = [UIColor blackColor];
headingLabel.textColor = [UIColor redColor];
[self.view addSubview:headingLabel];
[headingLabel setUserInteractionEnabled:YES];
headingLabel.text = _textField.text;
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panDetected:)];
[self.view addGestureRecognizer:panRecognizer];
[headingLabel addGestureRecognizer:panRecognizer];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapDetected:)];
[self.view addGestureRecognizer:tapRecognizer];
[headingLabel addGestureRecognizer:tapRecognizer];
}
(void)panDetected:(UIPanGestureRecognizer *)paramSender{
if (paramSender.state != UIGestureRecognizerStateEnded &&
paramSender.state != UIGestureRecognizerStateFailed){
CGPoint location = [paramSender locationInView:paramSender.view.superview];
paramSender.view.center = location;
}
}
(void) tapDetected:(UITapGestureRecognizer *)paramSender {
NSUInteger touchCounter = 0;
for (touchCounter = 0;
touchCounter < paramSender.numberOfTouchesRequired;
touchCounter++){
CGPoint touchPoint =
[paramSender locationOfTouch:touchCounter
inView:paramSender.view];
}
}
@end
答案 0 :(得分:0)
您必须使用视图委托方法:
touchesBegan,touchesEnd ..