zoukankan      html  css  js  c++  java
  • 详细控件编写

      
    @interface MainViewController : UIViewController  
      
    @property (strong, nonatomic) UIButton *myBtn;  
    @property (strong, nonatomic) UISlider *mySlider;  
    @property (strong, nonatomic) UISwitch *mySwitch;  
    @property (strong, nonatomic) UISegmentedControl *mySc;  
      
    @end</span>  
    
    MainViewController.m
    
     
    
     
    
    [cpp] view plaincopy
    
    <span style="font-size:10px;">#import "MainViewController.h"  
      
    @interface MainViewController ()  
      
    @end  
      
    @implementation MainViewController  
    @synthesize myBtn,mySlider,mySwitch,mySc;  
      
    - (void)viewDidLoad  
    {  
        // 加载UIView  
        UIView *mainView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];  
        mainView.backgroundColor = [UIColor whiteColor];  
        self.view = mainView;  
        [mainView release];  
          
        // 创建一个Button按钮  
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
        btn.frame = CGRectMake(100, 30, 57, 57);  
        [btn setTitle:@"Button" forState:UIControlStateNormal];  
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];  
        [btn setBackgroundImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];  
        [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];  
        myBtn = btn;  
        [self.view addSubview:myBtn];  
          
          
        // 创建一个Slider划块按钮  
        UISlider *slider = [[[UISlider alloc] initWithFrame:CGRectMake(50, 180, 200, 10)] autorelease];  
        slider.minimumValue = 0.0f;  
        slider.maximumValue = 100.0f;  
        slider.value = 50.0f;  
        [slider addTarget:self action:@selector(onChange:) forControlEvents:UIControlEventTouchUpInside];  
        mySlider = slider;  
        [self.view addSubview:mySlider];  
          
        // 创建一个UISwitch开关按钮  
        UISwitch *sbtn = [[[UISwitch alloc] initWithFrame:CGRectMake(50, 210, 200, 50)] autorelease];  
        [sbtn addTarget:self action:@selector(onSwitch:) forControlEvents:UIControlEventTouchUpInside];  
        mySwitch = sbtn;  
        [self.view addSubview:mySwitch];  
          
        // 创建一个UISegmentedControl  
        NSArray *btnList = [NSArray arrayWithObjects:@"left",@"center",@"right", nil];  
        UISegmentedControl *sc = [[[UISegmentedControl alloc] initWithItems:btnList] autorelease];  
        sc.frame = CGRectMake(50, 250, 200, 60);  
        [sc addTarget:self action:@selector(onSelect:) forControlEvents:UIControlEventTouchUpInside];  
        mySc = sc;  
        [self.view addSubview:mySc];  
          
        [super viewDidLoad];  
    }  
      
    @interface MainViewController : UIViewController  
      
    @property (strong, nonatomic) UIButton *myBtn;  
    @property (strong, nonatomic) UISlider *mySlider;  
    @property (strong, nonatomic) UISwitch *mySwitch;  
    @property (strong, nonatomic) UISegmentedControl *mySc;  
      
    @end</span>  
    
    MainViewController.m
     
    
     
    
    [cpp] view plaincopy
    
    <span style="font-size:10px;">#import "MainViewController.h"  
      
    @interface MainViewController ()  
      
    @end  
      
    @implementation MainViewController  
    @synthesize myBtn,mySlider,mySwitch,mySc;  
      
    - (void)viewDidLoad  
    {  
        // 加载UIView  
        UIView *mainView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];  
        mainView.backgroundColor = [UIColor whiteColor];  
        self.view = mainView;  
        [mainView release];  
          
        // 创建一个Button按钮  
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
        btn.frame = CGRectMake(100, 30, 57, 57);  
        [btn setTitle:@"Button" forState:UIControlStateNormal];  
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];  
        [btn setBackgroundImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];  
        [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];  
        myBtn = btn;  
        [self.view addSubview:myBtn];  
          
          
        // 创建一个Slider划块按钮  
        UISlider *slider = [[[UISlider alloc] initWithFrame:CGRectMake(50, 180, 200, 10)] autorelease];  
        slider.minimumValue = 0.0f;  
        slider.maximumValue = 100.0f;  
        slider.value = 50.0f;  
        [slider addTarget:self action:@selector(onChange:) forControlEvents:UIControlEventTouchUpInside];  
        mySlider = slider;  
        [self.view addSubview:mySlider];  
          
        // 创建一个UISwitch开关按钮  
        UISwitch *sbtn = [[[UISwitch alloc] initWithFrame:CGRectMake(50, 210, 200, 50)] autorelease];  
        [sbtn addTarget:self action:@selector(onSwitch:) forControlEvents:UIControlEventTouchUpInside];  
        mySwitch = sbtn;  
        [self.view addSubview:mySwitch];  
          
        // 创建一个UISegmentedControl  
        NSArray *btnList = [NSArray arrayWithObjects:@"left",@"center",@"right", nil];  
        UISegmentedControl *sc = [[[UISegmentedControl alloc] initWithItems:btnList] autorelease];  
        sc.frame = CGRectMake(50, 250, 200, 60);  
        [sc addTarget:self action:@selector(onSelect:) forControlEvents:UIControlEventTouchUpInside];  
        mySc = sc;  
        [self.view addSubview:mySc];  
          
        [super viewDidLoad];  
    }  
      
    @interface MainViewController : UIViewController  
      
    @property (strong, nonatomic) UIButton *myBtn;  
    @property (strong, nonatomic) UISlider *mySlider;  
    @property (strong, nonatomic) UISwitch *mySwitch;  
    @property (strong, nonatomic) UISegmentedControl *mySc;  
      
    @end</span>  
    
    MainViewController.m
     
    
     
    
    [cpp] view plaincopy
    
    <span style="font-size:10px;">#import "MainViewController.h"  
      
    @interface MainViewController ()  
      
    @end  
      
    @implementation MainViewController  
    @synthesize myBtn,mySlider,mySwitch,mySc;  
      
    - (void)viewDidLoad  
    {  
        // 加载UIView  
        UIView *mainView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];  
        mainView.backgroundColor = [UIColor whiteColor];  
        self.view = mainView;  
        [mainView release];  
          
        // 创建一个Button按钮  
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
        btn.frame = CGRectMake(100, 30, 57, 57);  
        [btn setTitle:@"Button" forState:UIControlStateNormal];  
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];  
        [btn setBackgroundImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];  
        [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];  
        myBtn = btn;  
        [self.view addSubview:myBtn];  
          
          
        // 创建一个Slider划块按钮  
        UISlider *slider = [[[UISlider alloc] initWithFrame:CGRectMake(50, 180, 200, 10)] autorelease];  
        slider.minimumValue = 0.0f;  
        slider.maximumValue = 100.0f;  
        slider.value = 50.0f;  
        [slider addTarget:self action:@selector(onChange:) forControlEvents:UIControlEventTouchUpInside];  
        mySlider = slider;  
        [self.view addSubview:mySlider];  
          
        // 创建一个UISwitch开关按钮  
        UISwitch *sbtn = [[[UISwitch alloc] initWithFrame:CGRectMake(50, 210, 200, 50)] autorelease];  
        [sbtn addTarget:self action:@selector(onSwitch:) forControlEvents:UIControlEventTouchUpInside];  
        mySwitch = sbtn;  
        [self.view addSubview:mySwitch];  
          
        // 创建一个UISegmentedControl  
        NSArray *btnList = [NSArray arrayWithObjects:@"left",@"center",@"right", nil];  
        UISegmentedControl *sc = [[[UISegmentedControl alloc] initWithItems:btnList] autorelease];  
        sc.frame = CGRectMake(50, 250, 200, 60);  
        [sc addTarget:self action:@selector(onSelect:) forControlEvents:UIControlEventTouchUpInside];  
        mySc = sc;  
        [self.view addSubview:mySc];  
          
        [super viewDidLoad];  
    }  
  • 相关阅读:
    指针和引用作为函数参数传递
    cv::Mat.type()
    Matlab 双目标定工具箱
    invalid conversion from `const void*' to `void*'
    error: 'vector' is not a member of cv
    单例模式与静态成员
    RGBD SLAM V2 +Ubuntu 16.04+ROS KINETIC配置及运行
    EntityFrameworkCore + MySQL 主从复制应用读写分离
    Docker 搭建 MySQL8.0 主从复制环境
    Asp.Net Core 项目中使用 Serilog 输出日志到 Elasticsearch
  • 原文地址:https://www.cnblogs.com/lidongq/p/3850125.html
Copyright © 2011-2022 走看看