zoukankan      html  css  js  c++  java
  • [置顶] Objective-C ,ios,iphone开发基础:自定义控件:Eg: UIButton

    第一步:新建一个工程,在 .h文件中坐如下声明:

    #import <UIKit/UIKit.h>
    
    @interface MyButtonViewController : UIViewController{
       
        UIButton* myButton;
        
    }
    
    @property (nonatomic,retain)UIButton *myButton;


    在. m 文件中

    #import "MyButtonViewController.h"
    
    @interface MyButtonViewController ()
    
    @end
    
    @implementation MyButtonViewController
    @synthesize myLable,topic,form,contentField,contentLable,contentSwitch,myButton;
    - (void)viewDidLoad
    {
        //创建自定义控件,代码实现
        CGRect frame = CGRectMake(105.0f, 150.0f, 100.0f, 50.0f);  //位置
        myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //初始化
        [myButton setTitle:@"Click here" forState:normal]; //设置标题以及其他属性
        myButton.frame = frame;
        [self.view addSubview:self.myButton]; //将UIButton  添加在视图上。
       
        [super viewDidLoad];
    	// Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)viewDidUnload
    {
        
        [super viewDidUnload];
        // Release any retained subviews of the main view.
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
        } else {
            return YES;
        }
    }
    
    -(void) dealloc{
        
        [myButton release];
        
        [super dealloc];
    }
    
    
    //实现键盘隐藏:
    -(IBAction)resignResponder
    {
        [topic resignFirstResponder];
        [form resignFirstResponder];
    }
    
    


  • 相关阅读:
    centos8上添加sudoer用户
    centos平台scp通过密钥远程复制文件(免密登录)
    使用 TestNG 并发测试 ;
    maven 添加tomcat依赖
    maven Web项目中POM的配置信息
    找xpath好用的工具(比较少用,针对只能在IE上打开的网站)
    maven 实践 :管理依赖
    maven将依赖打入jar包
    maven scope含义的说明
    Maven编译打包出错:找不到符号
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3281317.html
Copyright © 2011-2022 走看看