English 中文(简体)
最佳做法类别
原标题:Categories best practices

对于我以前可能曾使用过继承权的一些事情,我正在使用`这些'分类

我现在正在做的更是一个最佳做法问题, 我不知道该如何执行。 我正在写一个“代码>UIactivityIndicator View

<强> 类别:

@interface UIActivityIndicatorView (Customizations)
    - (UIActivityIndicatorView *) inView:(UIView *) target;
@end

<强 > 执行:

@implementation UIActivityIndicatorView (Customizations)

- (UIActivityIndicatorView *) inView:(UIView *) target {
    [self startAnimating];
    [self setHidden:NO];
    self.frame = target.bounds;
    self.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.6f];

    return self;
}
@end

(b) “强”和“强”

[background addSubview:[loader inView:background]];

我猜另一种方法就是让一个初始化功能 来选择容器的视图, 只需返回“ 刻式” 视图, 或者不返回任何东西( evue ), 并且让这个方法来给它打字 。

因此,我正在寻求关于如何处理这个问题的一些指导。

最佳回答

最让我担心的是,我实际上正在做第二份 UI Aactivity Indicator View 似乎没有必要

不,你不知道,你可能会被你从分类方法中 自我回归的事实所混淆, 但这只是一个指示器, 而不是被复制的对象本身。

不过,我在执行时将稍有不同:

- (void) addToSuperView:(UIView *) target {
    [self startAnimating];
    [self setHidden:NO];
    self.frame = target.bounds;
    self.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.6f];

    [target addSubview:self];
}

这样,在添加时,你不需要做一个额外的、不必要的电话:

[loader addToSuperView:background];
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签