There is no public Apple API to deep copy a UILabel. Your best bet is to make a helper method which copies all the parts you care about.
- (UILabel *)deepLabelCopy:(UILabel *)label {
UILabel *duplicateLabel = [[UILabel alloc] initWithFrame:label.frame];
duplicateLabel.text = label.text;
duplicateLabel.textColor = label.textColor;
// etc... anything else which is important to your ULabel
return [duplicateLabel autorelease];
}
If you want to use it all over your code base you can change it to a static method and put it in some sort of utility class. If you named the class LabelUtils
you could do something like...
+ (UILabel *)deepLabelCopy(UILabel *)label {
// ...
}
and would be called using UILabel *dupLabel = [LabelUtils deepLabelCopy:origLabel];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…