gpt4 book ai didi

ios - 如何将 Uilabel 文本设置为 nil +iphone

转载 作者:行者123 更新时间:2023-11-29 04:05:52 24 4
gpt4 key购买 nike

我有动态 UIButtons,其 subview 是 UIlabel。我的要求是第一次在一个按钮中显示一个标签文本,根据用户选择(长按按钮)后需要更新特定的按钮 subview 标签文本并删除其余的按钮 subview 标签文本。

我尝试过这种方式

for (int i=0; i < [arr count]; i++) 
{
UILabel *myLbl = [[UILabel alloc] initWithFrame:CGRectMake(30, 70, 60, 21)];
if (myissue.tag ==1) {
myLbl.text = @"Default";
}else {
myLbl.text = @"";
}
myLbl.backgroundColor = [UIColor clearColor];
myLbl.textColor = [UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0];
[myLbl setFont:[UIFont fontWithName:@"Helvetica" size:12]];
myLbl.textAlignment = NSTextAlignmentCenter;
myLbl.tag = i+1;
[myButton addSubview:defaultLbl];
[myLbl release];
}

And for retrieving the UILabel text
- (void)longPressTap:(UILongPressGestureRecognizer *)sender
{
if ([recognizer.view tag]) {
for (UIButton *btn in scrollView.subviews) {
UIButton *btnTag = (UIButton *)btn;
NSLog(@"--sv:%@", btn.subviews);
if (recognizer.view.tag == btnTag.tag){
[[btn.subviews objectAtIndex:3] text] ;
}else {

[[btn.subviews objectAtIndex:3] textAttributesForNil] ;
}
}
}
}

}

我的问题是我无法选择按钮 subview 标签文本并删除按钮标签文本的其余部分。请帮助我。

最佳答案

您不需要添加标签作为按钮的 subview ,按钮已经有自己的文本标签,可以使用[button setTitle:(NSString *) forState:(UIControlState)]设置

并删除文本,只需设置seTitle:@""

关于ios - 如何将 Uilabel 文本设置为 nil +iphone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15241263/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com