我正在创建一个带有属性字符串的UILabel
并将其分配给导航栏标题。它显示在我想要的地方。我还想附加它UITapGestureRecognizer
但我无法在识别器中调用该函数。下面你可以看到我正在尝试的代码。
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];
答案 0 :(得分:0)
<强>步骤1 强>
最初检查一次setUserInteractionEnabled:YES
或不
[label setUserInteractionEnabled:YES];
<强>步骤-2 强>
else check once frame and clickable area
<强>步骤-3 强>
添加所需的点击次数
tapGesture.numberOfTapsRequired = 1;
答案 1 :(得分:0)
将框架重置为CGRectZero
标签