是否可以在UILabel中找到文本的确切位置? (例如,如果标签的宽度可以变化,但文本可以右对齐或左对齐)
可能?不可能?不值得努力?
答案 0 :(得分:0)
如果您问如何检测标签当前文本对齐的状态,可以使用:
if (myLabel.textAlignment == UITextAlignmentLeft) {
//do something for left alignment
}else if (myLabel.textAlignment == UITextAlignmentRight){
//do something for right alignment
}else{
//do something for center alignment
}
要使标签“可点击”,您可以通过在标签上启用用户互动并添加UITapGestureRecognizer
来完成此操作。
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(someMethod:)];
[tap setDelegate:self];
[tap setNumberOfTapsRequired:1];
[tap setNumberOfTouchesRequired:1];
[myLabel addGestureRecognizer:tap];