我正在尝试为 UIActivityIndicatorView 创建一个类类别 - 我想将它设置在屏幕中心。
于是我宣布:
@implementation UIActivityIndicatorView(Normalize)
-(UIActivityIndicatorView *) setAtScreenCenter{
CGRect r = [UIScreen mainScreen].applicationFrame;
CGRect wheelR = CGRectMake(r.size.width / 2 - 12, r.size.height / 2 - 12, 24, 24);
self = [[UIActivityIndicatorView alloc] initWithFrame:wheelR];
self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
self.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
return self;
}
@end
用法:[activityWheel setAtScreenCenter];
但是,我得到一个编译错误:
Cannot assign to 'self' outside of a method in the init family