使用 hash函数。
#import <UIKit/UIKit.h>
@interface UIView (StringTag)
-(void) stringTag:(NSString*) tag;
-(UIView*) viewWithStringTag:(NSString*)tag;
@end
#import "UIView+StringTag.h"
@implementation UIView (StringTag)
-(void) stringTag:(NSString *)tag
{
[self setTag:[tag hash]];
}
-(UIView *)viewWithStringTag:(NSString *)tag
{
return [self viewWithTag:[tag hash]];
}
@end
UIView* view = [[UIViewalloc]init];
[view stringTag:@"ABC"];
[self.view addSubview:view];
UIView* v = [self.view viewWithStringTag:@"ABC"];