質問

I need to segue to another view when the user taps either of the information labels shown in the image below (above the colored riser bars):

enter image description here

It looks like I can implement such a solution using the label itself. However, it seems a little convoluted, and since I'm pretty green I avoid convolution anytime I can.

But while I have no experience with UIGestureRecognizer, I am reasonably comfortable with buttons. Would it be a breach of best practice to just place a button with a transparent background (indicated here by the black rectangle) on top of the label in question?

役に立ちましたか?

解決

I think you should do neither. Instead replace the label with an UIButton. As buttons use labels to display it's text, you can achieve the same look without having to deal with transparent buttons or extra objects like the gesture recognizer.

他のヒント

Hi you have two choices : Create an UItapgesture recognizer for each UIlabel or add UIButton with background transparent but I think the best way it's to create UItapGestureRecognizer for each UIlabel

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(respondToTapGesture:)];

[yourLabel addGestureRecognizer:tapRecognizer];

Of course implement the selector respondToTapGesture.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top