ast*_*ter 1 objective-c uilabel ios
我正在使用以下代码来创建我的视图.我UILabel在滚动视图中.现在我想在touchesBegan我的自定义标签的方法中点击事件.但无法得到它.
img1 = [[customLabel alloc] initWithFrame:CGRectMake(0,height ,280,10 )];//
[img1 setText: [self.answer_set objectAtIndex:i]];
[img1 setTextAlignment:NSTextAlignmentLeft];
[img1 setBackgroundColor:[UIColor colorWithRed:127.0f/255.0f green:165.0f/255.0f blue:234.0f/255.0f alpha:1.0f]];
img1.textColor = [UIColor whiteColor];
img1.lineBreakMode = NSLineBreakByWordWrapping;
img1.numberOfLines = 0;
[img1 sizeToFit];
img1.contentMode = UIViewContentModeScaleToFill;
img1.font = [UIFont fontWithName:@"Arial" size:14.0f] ;
CGFloat labelHeight=[self getStringHeightforLabel:img1];
NSLog(@"LABEL HEIGHT:: %f",labelHeight);
//set frame after getting height
if (labelHeight < 60.0) {
labelHeight = 60.0;
}
[img1 setUserInteractionEnabled:YES];
img1.tag = 5000;
img1.frame=CGRectMake(-5,height,285 + 10,labelHeight + 10);
img1.layer.cornerRadius = 5;
/** Shadow */
CALayer *shadowLayer = [[CALayer alloc] init];
shadowLayer.frame = CGRectMake(-5,height ,img1.frame.size.width,img1.frame.size.height);
shadowLayer.cornerRadius = 10;
shadowLayer.backgroundColor = [UIColor blueColor].CGColor;
shadowLayer.shadowColor = [UIColor colorWithRed:127.0f/255.0f green:165.0f/255.0f blue:234.0f/255.0f alpha:1.0f].CGColor;
shadowLayer.shadowOpacity = 0.6;
shadowLayer.shadowOffset = CGSizeMake(0,0);
shadowLayer.shadowRadius = 5;
[img1.layer setMasksToBounds:YES];
[shadowLayer addSublayer:img1.layer];
[self.ans_labels.layer addSublayer:shadowLayer];
height += img1.frame.size.height + 15;
Run Code Online (Sandbox Code Playgroud)
并获得活动:
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [touches anyObject];
NSLog(@"worked",nil);
//[self giveAnswer:touch.view.tag];
if(touch.view.tag == 5000){
// do here
}
}
Run Code Online (Sandbox Code Playgroud)
我能够提前得到活动,但不是今天.我做错了什么???
yourLabel.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap)];
tapGesture.delegate=self;
[yourLabel addGestureRecognizer:tapGesture];
- (void)labelTap:(UITapGestureRecognizer *)recognize {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2208 次 |
| 最近记录: |