iOS_不常用方法总结

获取某个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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值