我希望能够在点击和拖动标签时更改标签的边框颜色,并且在不点击和拖动标签时,边框颜色应该返回到以前的颜色。我已经使用了平移和点击手势识别器,但我不知道编写代码来改变它。这是我下面的代码:
(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