Ich erstelle eine UILabel
mit attributierter Zeichenfolge und weisen Sie sie dem Navigationsleistentitel zu. Es wird angezeigt, wo ich will. Ich möchte es auch anhängen UITapGestureRecognizer
, aber ich kann nicht die Funktion in der Erkennung genannt. Unten können Sie den Code sehen, den ich versuche.UITapGestureRecognizer reagiert nicht auf Berührung
label = [[UILabel alloc] initWithFrame:CGRectZero];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.numberOfLines = 4;
// set different font for title and subtitle
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"\n Title \n \n"];
//[string addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:1.0] range:NSMakeRange(0,string.length)];
// set line spacing
NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init];
[paragrahStyle setLineSpacing:-10];
[paragrahStyle setAlignment:NSTextAlignmentCenter];
[string addAttribute:NSParagraphStyleAttributeName value:paragrahStyle range:NSMakeRange(0, [string length])];
label.font = [UIFont fontWithName:@"Avenir-Medium" size:22.0f];
self.navigationItem.titleView = label;
label.attributedText = string;
[label sizeToFit];
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(clickTitleLabel)];
[label addGestureRecognizer:tapGesture];
Vielleicht '[label setUserInteractionEnabled: YES];'? – nynohu
Ah, ja, auf jeden Fall. – birdcage