[置顶] Objective-C ,ios,iphone开发基础:自定义控件:Eg: UIButton
2013-08-25 21:00
465 查看
第一步:新建一个工程,在 .h文件中坐如下声明:
在. m 文件中
#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]; }
相关文章推荐
- Objective-C ,ios,iphone开发基础:自定义控件:Eg: UIButton
- [置顶] Objective-C ,/,ios,/iphone开发基础:协议(protocol)
- [置顶] Objective-C ,ios,iphone开发基础:命名规范
- [置顶] Objective-C ,ios,iphone开发基础:ios数据库(The SQLite Database),使用终端进行简单的数据库操作
- [置顶] Objective-C ,ios,iphone开发基础:在UITextField输入完以后,隐藏键盘,
- [置顶] Objective-C ,ios,iphone开发基础:UIAlertView使用详解
- [置顶] Objective-C,/,ios,/iphone开发基础:分类(category,又称类别)
- [置顶] Objective-C ,ios,iphone开发基础:protocol 协议(委托,代理)的声明
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
- Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
- 疯狂iOS 讲义(上) Objective-C 2.0与iPhone/iPad应用开发基础
- Objective-C ,ios,iphone开发基础:UIAlertView使用详解
- Objective-C ,ios,iphone开发基础:picker控件详解与使用,(实现省市的二级联动)
- Objective-C ,ios,iphone开发基础:UIAlertView使用详解
- Objective-C ,ios,iphone开发基础:ios数据库(The SQLite Database),使用终端进行简单的数据库操作
- Objective-C ,ios,iphone开发基础:使用GDataXML解析XML文档,(libxml/tree.h not found 错误解决方案)
- Objective-C ,ios,iphone开发基础:ios数据库(The SQLite Database),使用终端进行简单的数据库操作
- Objective-C ,ios,iphone开发基础:如何判断一个字符是不是中文字符。计算一段字符串的长度。
- Objective-C ,ios,iphone开发基础:协议(protocol)
- Objective-C ,ios,iphone开发基础:JSON解析(使用苹果官方提供的JSON库:NSJSONSerialization)