iOS中的一些小知识点

来源:互联网 发布:大众软件 pdf 编辑:程序博客网 时间:2024/05/22 17:27
1.去掉导航栏下面的横线
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];

2.使UITableView上的cell点击后颜色消失

[tableView deselectRowAtIndexPath:indexPath animated:YES];

3.UIlabel自适应高度

CGSize descriptionSize = [descriptionLabel sizeThatFits:CGSizeMake(WIDTH-60, 1000000)];descriptionLabel.frame = CGRectMake(30,60, (WIDTH - 60), descriptionSize.height);

4.简单的状态栏 导航栏

隐藏状态栏

    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];

隐藏导航栏

[self.navigationController setNavigationBarHidden:YES];

5.RGB颜色转换

WTColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
6.普通颜色值
WTColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
7.圆角设置
view.layer.cornerRadius = 6;view.layer.masksToBounds = YES;
8.键盘关闭方法之一
- (void)setUpForDismissKeyboard {    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];    UITapGestureRecognizer *singleTapGR =    [[UITapGestureRecognizer alloc] initWithTarget:self                                            action:@selector(tapAnywhereToDismissKeyboard:)];    NSOperationQueue *mainQuene =[NSOperationQueue mainQueue];    [nc addObserverForName:UIKeyboardWillShowNotification                    object:nil                     queue:mainQuene                usingBlock:^(NSNotification *note){                    [self.view addGestureRecognizer:singleTapGR];                }];    [nc addObserverForName:UIKeyboardWillHideNotification                    object:nil                     queue:mainQuene                usingBlock:^(NSNotification *note){                    [self.view removeGestureRecognizer:singleTapGR];                }];}- (void)tapAnywhereToDismissKeyboard:(UIGestureRecognizer *)gestureRecognizer {    //此method会将self.view里所有的subview的first responder都resign掉    [self.view endEditing:YES];}
9.导航栏自带的又拉手势
self.navigationController.interactivePopGestureRecognizer.enabled = YES;self.navigationController.interactivePopGestureRecognizer.delegate = nil;
10.注册用户app发送推送弹出框
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
11.获取app版本号,名字
NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];  NSString* versionNum =[infoDict objectForKey:@"CFBundleVersion"];//版本名称  NSString*appName =[infoDict objectForKey:@"CFBundleDisplayName"];//app名称
12.使在运行程序的时候屏幕永远亮着
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
13.获取手机硬件信息
[[UIDevice currentDevice] systemName];[[UIDevice currentDevice] systemVersion];//os version[[UIDevice currentDevice] uniqueIdentifier];[[UIDevice currentDevice] model];[[UIDevice currentDevice] name];

一个很好的网址https://github.com/huang303513/iOS-Study-Demo


0 0