系統盤datePicker、調整Nav後退按鈕位置調整,電話簡訊郵件分享

躍然發表於2015-12-10

一、設定軟鍵盤為時間選擇器

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.indexPath = indexPath;
//獲取當前點選的cell
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

//為了點選cell的時候能彈出鍵盤
//生成文字框,並且讓文字框成為第一響應者
UITextField *txt = [UITextField new];
[cell addSubview:txt];

//設定鍵盤的工具欄
CZKeyboard *tool = [CZKeyboard keyboardTool];
tool.delegate = self;
txt.inputAccessoryView = tool;


//彈出datePicker
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
self.datePicker = datePicker;
datePicker.datePickerMode = UIDatePickerModeTime;
datePicker.backgroundColor = [UIColor lightGrayColor];

//把彈出鍵盤改成datePicker
txt.inputView = datePicker;

//讓文字框成為第一響應者,此處之前 應該先設定inputView
[txt becomeFirstResponder];
}

二、自定義後退按鈕位置調整


//如果tableView啟用分組的話。第一組之前會有空白。把空白去掉
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, -1)];

“`
//1 自定義後退按鈕
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@”NavBack”] originalImage] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)];

// 後退按鈕距離圖片距離左邊邊距
UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedItem.width = -10;

self.navigationItem.leftBarButtonItems = @[fixedItem,backItem];



//自定義後退按鈕後,手勢返回上一級控制器的功能恢復
self.navigationController.interactivePopGestureRecognizer.delegate = nil;
```

三、NSInterger格式問題

%ld
%d
%zd 根據當前系統判斷返回型別 64位 32位

四、電話分享、簡訊分享、郵件分享

  __weak typeof(self) weakSelf = self;

    CZItem *item1 = [CZItemArrow itemWithTitle:@"電話分享" icon:nil option:^{
        //通話完成會回到當前應用, 以前的時候不會回到當前應用
//        NSURL *url = [NSURL URLWithString:@"tel://54188"];
//        [[UIApplication sharedApplication] openURL:url];


        //打電話之前會有提示  回到當前應用   私有的api
//        NSURL *url = [NSURL URLWithString:@"telprompt://54188"];
//        [[UIApplication sharedApplication] openURL:url];

        NSURL *url = [NSURL URLWithString:@"tel://54188"];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [weakSelf.webView loadRequest:request];

    }];

    CZItem *item2 = [CZItemArrow itemWithTitle:@"簡訊分享" icon:nil option:^{

        //發完簡訊之後。會到簡訊介面
//        NSURL *url = [NSURL URLWithString:@"sms://54188"];
//        [[UIApplication sharedApplication] openURL:url];


        //判斷裝置是否能傳送資訊
        if (![MFMessageComposeViewController canSendText]) {
            return;
        }

        MFMessageComposeViewController *vc = [MFMessageComposeViewController new];
        //收件人列表
        vc.recipients = @[@"10000",@"10086"];
        vc.body = @"推薦一個nb的遊戲 http://www.nlcoder.com/test";
        vc.subject = @"biaoti";
        //設定代理
        vc.messageComposeDelegate = weakSelf;

        [weakSelf presentViewController:vc animated:YES completion:nil];

    }];

    CZItem *item3 = [CZItemArrow itemWithTitle:@"郵件分享" icon:nil option:^{

        //判斷是否能傳送郵件
        if (![MFMailComposeViewController canSendMail]) {
            return;
        }

        MFMailComposeViewController *vc = [MFMailComposeViewController new];

        vc.mailComposeDelegate = weakSelf;
        //設定收件人
        [vc setToRecipients:@[@"1111@itcast.cn",@"2222@itcast.cn"]];
        //密送
//        [vc setBccRecipients:<#(NSArray *)#>]
        //抄送
//        [vc setCcRecipients:<#(NSArray *)#>]

        [vc setSubject:@"收福利了"];
        [vc setMessageBody:@"送美女" isHTML:NO];

        //
        UIImage *img = [UIImage imageNamed:@"aa"];
        NSData *data = UIImagePNGRepresentation(img);

        [vc addAttachmentData:data mimeType:@"image/png" fileName:@"cls.png"];



        [weakSelf presentViewController:vc animated:YES completion:nil];

    }];

    //controller(self) --> self.groups -->  group  -->  item   --> option  --> self

    CZGroup *group = [CZGroup groupWithItems:@[item1,item2,item3]];
    self.groups = @[group];

如果你能夠在某個領域全身心投入一萬個小時,那麼你一定是那個領域的專家。

相關文章