ios 备忘录---你可能不知道的小知识点

  代码如下:
    
    1:直接打开app store 评论页面的URL,直接更换 后面的id号就可以
    
    // 通过  html 打开
    
http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=557853602
    
    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=557853602"]];
    
    // 直接通过 itunes 打开
    
    NSString *strUrl =@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=557853602";
    
    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:strUrl]];
    
    2: 更改 UIPageControl 图标
    -(void)pageControlStatusImage:(int)_page{
        NSArray *subview = self.firstPageControl.subviews; // 获取所有子视图
        for(NSInteger i =0; i < [subview count]; i++) {
            UIImageView *_dotView = [subview objectAtIndex:i];
            if (i == _page) {
                // image w = 6 h = 6
                _dotView.image = _pageNormalImage;
            } else {
                _dotView.image = _pageHighlightedImage;
            }
        }
    }
    
    3: UIAlertView  Frame
default frame x = 0.000000, y=0.000000, w=284.000000, h=141.000000
title: x = 12.000000, y=15.000000, w=260.000000, h=23.000000
message: x = 12.000000, y=45.000000, w=260.000000, h=21.000000
    left but: x = 11.000000, y=82.000000, w=127.000000, h=43.000000
    right but: x = 146.000000, y=82.000000, w=127.000000, h=43.000000
    
    4: ipad 上UIView 使用 Form Sheet Size 模式时,
    
    UITextField,  [textFieldresignFirstResponder] 不能关闭软键盘问题
    
    解决方法:
    
    在 .h .m 文件中 重写 disablesAutomaticKeyboardDismissal 方法
    - (BOOL)disablesAutomaticKeyboardDismissal;
    - (BOOL)disablesAutomaticKeyboardDismissal
    {
        return NO;
    }
    
    如果在  UINavigationController 中使用,可以用如下方法重写,之后在 需要用到的地方 import
    
    添加File:UINavigationController+KeyboardDismiss.h   UINavigationController+KeyboardDismiss.m
    
#import <Foundation/Foundation.h>
    // 解决 FromSheet UIView textfiled 不能 隐藏键盘的问题
    @interface UINavigationController (KeyboardDismiss)
    - (BOOL)disablesAutomaticKeyboardDismissal;
    @end
#import "UINavigationController+KeyboardDismiss.h"
    @implementation UINavigationController(KeyboardDismiss)
    - (BOOL)disablesAutomaticKeyboardDismissal
    {
        return NO;
    }
    @end
    
    
    5: UIActionSheet  最后一个 按钮 点击时不太好用,一般要点击道 button 上半部才行
    
    UIActionSheet *actionSheet = [[UIActionSheetalloc]
                                  
                                  initWithTitle:@“aaa”
                                  
                                  delegate:nil
                                  
                                  cancelButtonTitle:nil
                                  
                                  destructiveButtonTitle:nil
                                  
                                  otherButtonTitles:@"aaa",@"Cancel",nil];
    
    //[actionSheet showInView:self.view];    ---- 把这行换掉,用下行的方法来显示
    
    [actionSheetshowInView:[UIApplicationsharedApplication].keyWindow];
    
    6: UITableViw 的 cell 中 有 UITextFiled 控件,点击出来软件盘后,如果 UITableView  此时刷新 relaoddata,则软件盘会因为 失去 焦点而 自动隐藏
    
    如果想要 软件盘还在,则需要 改变 UITextFiled 的焦点 到 UITableViw 之外的 另一个 UITextFiled 上即可
    
    7:  ios 设备 左上角 网络请求状态 显示/隐藏
    
    //显示网络活动标志:
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    
    //隐藏网络活动标志:
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    
    8:设置UIButton中title的位置
    
    让UIButton的title居左对齐,设置btn.textLabel.textAlignment = UITextAlignmentLeft是没有作用的,
    
    需要设置btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;
    
    此时文字会紧贴到做边框,可以设置btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);使文字距离做边框保持10个像素的距离。
    
    // ---------------
    
    1、调用 自带mail
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hzlzh.com"]];
    
    2、调用 电话phone
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]];
    iOS应用内拨打电话结束后返回应用
    一般在应用中拨打电话的方式是:
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456789"]];
    
    使用这种方式拨打电话时,当用户结束通话后,iphone界面会停留在电话界面。
    用如下方式,可以使得用户结束通话后自动返回到应用:
    UIWebView*callWebview =[[UIWebView alloc] init];
    NSURL *telURL =[NSURL URLWithString:@"tel:10086"];// 貌似tel:// 或者 tel: 都行
    [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
    //记得添加到view上
    [self.view addSubview:callWebview];
    
     还有一种私有方法:(可能不能通过审核)
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://10086"]];
    
    3、调用自带 浏览器 safari
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.hzlzh.com"]];
    
    4、调用 SMS
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
    
    调用phone可以传递号码,调用SMS 只能设定号码,不能初始化SMS内容。
    
    若需要传递内容可以做如下操作:
    加入:MessageUI.framework
    
#import <MessageUI/MFMessageComposeViewController.h>
    
    实现代理:MFMessageComposeViewControllerDelegate
    
    调用sendSMS函数
    //内容,收件人列表
    - (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
    {
        
        MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
        
        if([MFMessageComposeViewController canSendText])
            
        {
            
            controller.body = bodyOfMessage;
            
            controller.recipients = recipients;
            
            controller.messageComposeDelegate = self;
            
            [self presentModalViewController:controller animated:YES];
            
        }
        
    }
    // 处理发送完的响应结果
    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
    {
        [self dismissModalViewControllerAnimated:YES];
        
        if (result == MessageComposeResultCancelled)
            NSLog(@"Message cancelled")
            else if (result == MessageComposeResultSent)
                NSLog(@"Message sent")
                else
                    NSLog(@"Message failed")
                    
                    }
    
    10文字加中划线(可以自定颜色,分段长度等)
    
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:label.text];
    [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid |NSUnderlineStyleSingle) range:NSMakeRange(0, label.text.length)];
    [attri addAttribute:NSStrikethroughColorAttributeName value:lineColor range:NSMakeRange(0, label.text.length)];
    [label setAttributedText:attri]
    
    11.UIView 添加背景图
    
    UIImage * img = [UIImage imageNamed:imgName];
    view.layer.contents = (id)img.CGImage;
    view.layer.backgroundColor = [UIColor clearColor].CGColor
    
    12多参
    
#define AA(p,...)  p, ##__VA_ARGS__
    
    13禁止系统休眠
    
    [UIApplication sharedApplication].idleTimeDisabled = YES
    
    14RGB颜色转换
    
    [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
    

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值