IOS学习之笔记碎记2

图片的拉伸
  1. UIImage *img=[UIImage imageNamed:@"imag"];  
  2. img=[img stretchableImageWithLeftCapWidth:15 topCapHeight:12];  
  3. UIImageView *imgView=[[UIImageView alloc]initWithImage:img];  
  4. [imgView setFrame:CGRectMake(1010200200)];  
  5. [self. view addSubview  
  6. 这里用的图片拉伸方法

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;

leftCapWidth是指leftCapWidth后面的一个想像素开始拉伸,topCapHeight距离topCapHeight的像素开始拉升

字体加粗 :[uifont boldSystemFontOfsize:20];

1身份证号

  1. + (BOOL) validateIdentityCard: (NSString *)identityCard  
  2. {  
  3.     BOOL flag;  
  4.     if (identityCard.length <= 0) {  
  5.         flag = NO;  
  6.         return flag;  
  7.     }  
  8.     NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";  
  9.     NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];  
  10.     return [identityCardPredicate evaluateWithObject:identityCard];  
  11. }  
2手机号
  1. + (BOOL) validateMobile:(NSString *)mobile  
  2. {  
  3.     //手机号以13, 15,18开头,八个 \d 数字字符  
  4.     NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";  
  5.     NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];  
  6.     return [phoneTest evaluateWithObject:mobile];  
  7. }  
3邮箱
  1. + (BOOL) validateEmail:(NSString *)email  
  2. {  
  3.     NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";  
  4.     NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];  
  5.     return [emailTest evaluateWithObject:email];  
  6. }  
ios推送通知设置

先要配置好相应的证书,之后

在APPDelegate文件中设置

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  2. {  
  3. ......  
  4. //消息推送注册  
  5.     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge];  
  6.       
  7.     //判断程序是不是由推送服务完成的  
  8.     if (launchOptions) {  
  9.         NSDictionary* pushNotificationKey = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];  
  10.         if (pushNotificationKey) {  
  11.             UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"推送通知"  
  12.                                                            message:@"这是通过推送窗口启动的程序,你可以在这里处理推送内容"  
  13.                                                           delegate:nil  
  14.                                                  cancelButtonTitle:@"知道了"  
  15.                                                  otherButtonTitles:nil, nil nil];  
  16.             [alert show];  
  17.         }  
  18.      }  
  19. ......  
  20. }  
向苹果注册推送通知

实现推送通知代理

  1. #pragma mark -------------  消息推送代理 -----------------  
  2.    
  3. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {  
  4.       
  5. //    NSString *token = [NSString stringWithFormat:@"%@", deviceToken];  
  6.       
  7.     NSString *token=[[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];  
  8.     token=[[token description] stringByReplacingOccurrencesOfString:@" " withString:@""];  
  9.   
  10. //    user_defaults_set_string(@"deviceToken",STRING_FORMAT(@"%@",token));  
  11.   
  12.   
  13.       
  14.     //获取终端设备标识,这个标识需要通过接口发送到服务器端,服务器端推送消息到APNS时需要知道终端的标识,APNS通过注册的终端标识找到终端设备。  
  15.     NSLog(@"My token is---------:%@", token);  
  16. }  
  17. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {  
  18.     NSString *error_str = [NSString stringWithFormat@"%@", error];  
  19.     NSLog(@"Failed to get token, error:%@", error_str);  
  20. }  
  21. -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo  
  22. {  
  23. /**********震动****************/  
  24.         AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)    
  25. /**********提示音****************/       
  26.         AudioServicesPlaySystemSound(107);  
  27.   //在此处理接收到的消息。  
  28.       
  29.     NSLog(@"Receive remote notification ------------------ : %@",userInfo);  
  30.  /************处理消息************/  
  31. }  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值