2

这更像是一个社区分享帖子,而不是一个真正的问题。在我的 iPhone OS 项目中,我总是导入一个带有有用方法的辅助类,我可以将其用于每个项目。

所以我认为这可能是一个好主意,如果每个人都分享一些他们最喜欢的方法,这些方法应该在每个人的工具箱中。

我将从 NSString 类的扩展开始,这样我就可以即时创建带有日期的字符串,提供格式和语言环境。也许有人可以从中找到一些需要。

   @implementation NSString (DateHelper)

+(NSString *) stringWithDate:(NSDate*)date withFormat:(NSString *)format withLocaleIdent:(NSString*)localeString{ 
 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    //For example @"de-DE", or @"en-US"
 NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:localeString];  
 [dateFormatter setLocale:locale];

    // For example @"HH:mm"
 [dateFormatter setDateFormat:format];  

 NSString *string = [dateFormatter stringFromDate:date];

 [dateFormatter release];
 [locale release];

 return string;  
} 
@end

我很想看看你的一些工具。

4

2 回答 2

1
@implementation NSTimer (ECC)

-(void) suspend:(BOOL)inSuspend {
    [self setFireDate:inSuspend ? [NSDate distantFuture] : [NSDate dateWithTimeIntervalSinceNow:[self timeInterval]]];
}

@end
于 2010-06-03T23:12:11.433 回答
1
@implementation UIDevice (OrientationAddition)
- (UIInterfaceOrientation)vagueOrientation {

    if ([[UIApplication sharedApplication] statusBarFrame].size.height > 40){
        return UIInterfaceOrientationLandscapeLeft;
    }

    return UIInterfaceOrientationPortrait;
}
@end

我在调用其他任何东西之前用它来确定方向,也在这个:

@implementation UIScreen (BoundsAddition)
- (CGRect)actualBounds {

    CGRect fakeBounds = self.bounds;
    if (UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] vagueOrientation])){
        return fakeBounds;
    }

    return CGRectMake(0, 0, fakeBounds.size.height, fakeBounds.size.width);
}
@end

它根据方向返回边界。

于 2010-06-03T23:04:01.593 回答