简体   繁体   English

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

[英]How to set Uilabel text to nil +iphone

I have dynamic UIButtons with subview is UIlabel. 我有带有子视图的动态UIButtons是UIlabel。 My requirement is to display one label text in one button first time, after based on user selection(long press on the button) need to update the particular button subview label text and remove rest of the button subview label text. 我的要求是,在基于用户选择(长按按钮)之后需要更新特定的按钮子视图标签文本并删除其余的按钮子视图标签文本之后,第一次在一个按钮中显示一个标签文本。

I tried in this way 我以这种方式尝试

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] ;
                }
            }
        }
    }

}

my problem is i was not able to selected button subview label text and removing rest of the button label text. 我的问题是我无法选择按钮子视图标签文本并删除其余的按钮标签文本。 please help me. 请帮我。

You shouldnt need to add a label as a subview for a button, buttons already have their own text label that can be set using [button setTitle:(NSString *) forState:(UIControlState)] 您不需要添加标签作为按钮的子视图,按钮已经具有自己的文本标签,可以使用[button setTitle:(NSString *) forState:(UIControlState)]

and to remove the text just set seTitle:@"" 并删除文本,只需设置seTitle:@""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM