zoukankan      html  css  js  c++  java
  • 常用控件补充(UIDatePicker、UIWebView)

    一、UIDatePicker日期拾取器对象

    - (void)viewDidLoad {

        [super viewDidLoad];

        //初始化日期拾取器对象

        UIDatePicker * datePicker = [[UIDatePicker alloc] init];

        //设置日期拾取器对象的中心位置

        [datePicker setCenter:CGPointMake(200, 200)];

        //设置日期拾取器的tag值,以便再次使用

        [datePicker setTag:1];

        

        [self.view addSubview:datePicker];

        

        //添加一个按钮,当点击按钮时获取日期拾取器对象的值

        CGRect rect = CGRectMake(110, 350, 100, 30);

        UIButton * button = [[UIButton alloc] initWithFrame:rect];

        [button setTitle:@"select" forState:UIControlStateNormal];

        [button setBackgroundColor:[UIColor purpleColor]];

        [button addTarget:self action:@selector(getDate) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:button];

    }

    - (void)getDate{

        //通过tag获取日期拾取器对象

        UIDatePicker * datePicker = (UIDatePicker *)[self.view viewWithTag:1];

        //获取日期拾取器的日期值

        NSDate * select = [datePicker date];

        //新建一个日期格式化对象,用来实现日期的格式化

        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];

        //设置日期的格式

        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];

        //将日期转换为字符串

        NSString * dateAndTime = [dateFormatter stringFromDate:select];

        //使用警告弹出窗口,显示日期结果

        UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"时间" message:dateAndTime preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:nil];

        [alertController addAction:okAction];

        [self presentViewController:alertController animated:YES completion:nil];

    }

    效果:

    二、UIWebView

    - (void)viewDidLoad {

        [super viewDidLoad];

    //    [self loadWeb];

        [self loadHTML];

    //1.UIWebView加载网页

    - (void)loadWeb{

        CGRect rect = CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 20);

        UIWebView * webView = [[UIWebView alloc] initWithFrame:rect];

        NSURL * url = [NSURL URLWithString:@"http://www.baidu.com"];

        //创建一个网址请求对象,作为网页视图对象的网络请求

        NSURLRequest * requestobj = [NSURLRequest requestWithURL:url];

        //使用网页视图对象,加载设置的网址

        [webView loadRequest:requestobj];

        [self.view addSubview:webView]; 

    }

    //2.UIWebViw加载本地HTML代码

    - (void)loadHTML{

        CGRect rect = CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 20);

        UIWebView * webView = [[UIWebView alloc] initWithFrame:rect];

        //新建一个HTML字符串

        NSString * htmlString = @"<font color='red'>Hello</font> <b>iOS</b> <i>programe</i>";

        [webView loadHTMLString:htmlString baseURL:nil];

        

        [self.view addSubview:webView];

     }

  • 相关阅读:
    springcloud-spring cloud config统一配置中心
    springcloud-hystrix断路器对微服务的容错处理
    springcloud-feign组件实现声明式的调用
    springcloud-Ribbon-负载均衡组件
    springcloud-Eureka-服务注册与发现核心组件
    springcloud入门-什么是springcloud
    Redis缓存设计及常见问题
    Lucene全文检索入门使用
    redis安装、使用
    nodejs环境 + 入门 + 博客搭建
  • 原文地址:https://www.cnblogs.com/HOYF/p/5153382.html
Copyright © 2011-2022 走看看