开发者

After adding a UILabel to my view, how do I delete it?

开发者 https://www.devze.com 2022-12-24 11:22 出处:网络
I have added a UILabel to my view programmatically like this: myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 30.0f)];

I have added a UILabel to my view programmatically like this:

myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 30.0f)];
myLabel.center = CGPointMake(160.0f, 120.0f);
myLabel.backgroundColor = [UIColor clearColor];
myLabel.textColor = [UIColor whiteColor];
myLabel.font = [UIFont fontWithName:@"Helvetica" size: 18.0];
myLabel.textAlignment = UITextAlignmentCenter;
myLabel.text = @"Hello";
[self.myView addSubview:myLabel];

To add a label to my view. What I can't seem to find out is once I'm done w/ the label (at a future point) how can I delete it from the view? [myLabel release] doesn't seem to work which I think makes sense because the view it's added to probably retained it's over reference. So what is th开发者_JAVA技巧e best practice?


[myLabel removeFromSuperview];
0

精彩评论

暂无评论...
验证码 换一张
取 消