在我的 iOS 应用程序中,我想要 UILabel,它可以在带有动态文本的大部分屏幕上使用。
因此,我在我的 Utility 类中编写了方法,它创建了具有关联 UIView 的 UILabel,并且我还将文本设置为我想要的 UILabel。 我使用这个 Utility 类方法在我想要的地方创建 UILabel
但是,我面临的问题是我无法从 View 中隐藏或删除此 UILabel。
所以请给我您宝贵的建议...
提前致谢......
+(void)drawLabel:(UIView *)view message:(NSString *)message
{
UILabel *messageLabel = [[UILabel alloc]init];
messageLabel.frame = CGRectMake(0, 0, 320, 30);
[messageLabel setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
messageLabel.text = message;
[messageLabel setCenter:view.center];
[messageLabel setTextAlignment:NSTextAlignmentCenter];
[view addSubview:messageLabel];
}
这是我在 Utility 类中编写的用于创建 UILabel 的方法。
[CACCustomMessageLabel drawLabel:self.view message:@"MY LABEL2"];
我像上面一样使用它。
最佳答案
您可以在实用程序类中创建这样的方法。
+(void)drawLabel:(UIView *)view message:(NSString *)message isHide:(BOOL)isHide
{
UILabel *messageLabel = [[UILabel alloc]init];
messageLabel.frame = CGRectMake(0, 0, 320, 30);
[messageLabel setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
messageLabel.text = message;
[messageLabel setCenter:view.center];
[messageLabel setTextAlignment:NSTextAlignmentCenter];
[view addSubview:messageLabel];
messageLabel.hidden = isHide;
}
这是我在 Utility 类中编写的用于创建 UILabel 的方法。这是用于在 View 中隐藏和取消隐藏标签的 isHide 参数。
[uilabelUtility drawLabel:self.view message:@"Jaydip Godhani" isHide:YES];
这里的 YES 是隐藏标签,不让你看到。
关于ios - 自定义 UILabel 类 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32782410/