获取某个view所在的控制器
- (UIViewController *)viewController {
UIViewController *viewController = nil;
UIResponder *next = self.nextResponder;
while (next)
{
if ([next isKindOfClass:[UIViewController class]])
{
viewController = (UIViewController *)next;
break;
}
next = next.nextResponder;
}
return viewController;
}
获取系统的字体类型和名称
- (void)getSystemFonts{
for(NSString *familyName in [UIFont familyNames]){
NSLog(@"%@",familyName);
NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
for(NSString *fontName in fontNames) {
NSLog(@"\t|- %@",fontName);
}
}
}
禁止锁屏
[UIApplication sharedApplication].idleTimerDisabled = YES;
iOS跳转到App Store下载应用评分
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:@"itms-apps://itunes.apple.com/WebObjects/
MZStore.woa/wa/viewContentsUserReviews?
type=Purple+Software&id=APPId"]];
更改状态栏的颜色
- (void)setStatusBarBackgroundColor:(UIColor *)color {
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
statusBar.backgroundColor = color;
}
}
修改UITextField中Placeholder的文字颜色
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
获取手机安装的应用
Class c =NSClassFromString(@"LSApplicationWorkspace");
id s = [(id)c performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSArray *array = [s performSelector:NSSelectorFromString(@"allInstalledApplications")];
for (id item in array) {
NSLog(@"%@",[item performSelector:NSSelectorFromString(@"applicationIdentifier")]);
NSLog(@"%@",[item performSelector:NSSelectorFromString(@"bundleIdentifier")]);
NSLog(@"%@",[item performSelector:NSSelectorFromString(@"bundleVersion")]);
NSLog(@"%@",[item performSelector:NSSelectorFromString(@"shortVersionString")]);
}
获取到webview的高度
CGFloat height = [[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
设置navigationBar的title
//选择的颜色
UIColor * color = [UIColor whiteColor];
NSDictionary * dict = [NSDictionary dictionaryWithObject:color forKey:UITextAttributeTextColor];
//设置
self.navigationBar.titleTextAttributes = dict;
常用工具
视图透明,而子视图不透明
[[UIColor blackColor] colorWithAlphaComponent:0.6]]
监听数组变化
@property (nonatomic, strong) NSMutableArray *cellList;
- (NSMutableArray *)cellListWrapper {
return [self mutableArrayValueForKey:@"cellList"];
}
等宽字体,可用于数组对齐和时间显示等
下列几种字体是 iPhone 上的设备字体:
• Serif:Times New Roman、 Georgia 和 _serif
• Sans-serif:Helvetica、 Arial、 Verdana、 Trebuchet、 Tahoma 和 _sans
• 等宽字体:Courier New、 Courier 和 _typewriter、Helvetica Neue