2011-12-23 11 views
9

私は、画面上に表示するためにプログラムによっていくつかのセットのラベルを作成しました。iphoneのUILabelに関するアクション

UIButtonについて私に示唆しないでください。私はUILabelのためにそれをしたい。ラベルをクリックすると、別の詳細ビューが表示されます。

この問題は、Inteface Builderを使用せずに解決してください。

+1

UIButtonに問題がありますか?透明なUIbuttonは、あなたが望むものと何の違いもないと思います。 – Skyler

答えて

22

は最終的に私が思い付いてみ

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
....... 
....... 
CGPoint touch;//Touch Location 

if(CGRectContainsPoint([objectOfLable frame], [touch locationInView:self.view ])) 
{ 
    Do What you Want 
} 

} 

CGRectContainsPoint(label.frame,touchCoordinate) 
{ 
//you got the touch action on your label 
} 
4

CGPointを引き出し、あなたのコントローラでtouchesBeginを実装して、あなたのラベルのIBoutletを作る - この

+1

pls IBなしで私に教えてください –

+1

ラベルのタグを作成中に設定してください:set tag:199を持っているとします。次に、必要に応じてUILabel * label = [self.view viewWithTag:199]でラベルを取得できます。 – samfisher

+1

上記を使用してIBOutletなしでラベルのオブジェクトを取得できます。私はそれが助けてくれることを願って.. – samfisher

3

をチェックし、touchCoordinateをソリューションと私は結果を得た

[titleLbl setUserInteractionEnabled:YES]; 
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelButton:)]; 
    [tapGestureRecognizer setNumberOfTapsRequired:1]; 
    [titleLbl addGestureRecognizer:tapGestureRecognizer]; 
    [tapGestureRecognizer release]; 
関連する問題