第一步:新建一个工程,在 .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];
}

[置顶] Objective-C ,ios,iphone开发基础:自定义控件:Eg: UIButton的更多相关文章

  1. [置顶] 提高生产力:Web开发基础平台WebCommon的设计和实现

    Web开发中,存在着各种各样的重复性的工作.为了提高开发效率,不在当码农,我在思考和实践如何搭建一个Web开发的基础平台. Web开发基础平台的目标和功能 1.提供一套基础的开发环境,整合了常用的框架 ...

  2. [置顶] Objective-C ,ios,iphone开发基础:UIAlertView使用详解

    UIAlertView使用详解 Ios中为我们提供了一个用来弹出提示框的类 UIAlertView,他类似于javascript中的alert 和c#中的MessageBox(); UIAlertVi ...

  3. [置顶] Objective-C ,ios,iphone开发基础:protocol 协议(委托,代理)的声明

    协议是为了弥补Objective-c中类只能单继承的缺陷,在Objective-c2.0之前当一个类遵循一个协议的时候,必须在类中实现协议的所有方法,在Objective-c2.0之后协议中的方法就有 ...

  4. [置顶] Objective-C,/,ios,/iphone开发基础:分类(category,又称类别)

    在c++中我们可以多继承来实现代码复用和封装使程序更加简练.在objective-c中只能单继承,不能多继承,那么除了协议protocol之外,我们可以实现类似多继承的一个方法就是,分类(catego ...

  5. [置顶] Objective-C ,ios,iphone开发基础:在UITextField输入完以后,隐藏键盘,

    在x-code Version 4.3.2 (4E2002)下编译: 在 Controller. m 文件下添加如下实例方法即可: - (void)viewDidUnload { [super vie ...

  6. [置顶] Objective-C ,/,ios,/iphone开发基础:协议(protocol)

    protocol协议时为了补充Objective-C 只能单继承的缺陷而增加的一个新功能.Objective-C重所有的方法都是虚方法,所以在oc重也就没有关键字 virtual一说,有了协议可以补充 ...

  7. [置顶] Objective-C ,ios,iphone开发基础:ios数据库(The SQLite Database),使用终端进行简单的数据库操作

    SQLite  是一个轻量级的免费关系数据库.SQLite最初的设计目标是用于嵌入式系统,它占用资源非常少,在嵌入式设备中,只需要几百K的内存就够了,可以在(http://www.sqlite.org ...

  8. [置顶] Objective-C ,ios,iphone开发基础:命名规范

    命名规范:http://bukkake.iteye.com/blog/695492  点击打开链接

  9. Objective-C ,ios,iphone开发基础:使用GDataXML解析XML文档,(libxml/tree.h not found 错误解决方案)

    使用GDataXML解析XML文档 在IOS平台上进行XML文档的解析有很多种方法,在SDK里面有自带的解析方法,但是大多情况下都倾向于用第三方的库,原因是解析效率更高.使用上更方便 这里主要介绍一下 ...

随机推荐

  1. c3p0数据源定义

    <!-- c3p0 connection pool configuration --> <bean id="testDataSource" class=" ...

  2. pyqt小例子 treewidget

    # -*- coding: cp936 -*- from PyQt4.QtCore import * from PyQt4.QtGui import * class InlineEditor(QWid ...

  3. pyqt一个小例子

    # -*- coding: utf-8 -*- __author__ = 'Administrator' from PyQt4 import Qt,QtCore,QtGui import sys,ra ...

  4. ERROR 1 (HY000): Can't create/write to file '/tmp/#sql_909_0.MYI' (Errcode: 13)

    mysql> desc tablename; ERROR 1 (HY000): Can't create/write to file '/tmp/#sql_909_0.MYI' (Errcode ...

  5. 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)

    0.表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * from user ...

  6. 页面全部加载完毕和页面dom树加载完毕

    dom树加载完毕 $(document).ready()//原生写法document.ready = function (callback) {            ///兼容FF,Google   ...

  7. String功能测试

    package foxe; import java.io.IOException;import java.util.StringTokenizer; public class MainClass { ...

  8. JS中的for和for in循环

    1.for循环通常用来遍历数组或类数组对象 模式1:长度缓存 for(var i=0,max=arr.length;i<max;i++){ //your code } 模式2:逐减,与零比较比与 ...

  9. poj3122 binary search 实数区间

    Pie Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14536   Accepted: 4979   Special Ju ...

  10. windows应用中调用DLL一步步试验

    试验环境: PC:win10 build 10143 IDE: vs2015 RC WinPhone: win10 build 10136 简单界面,点按钮,算加法 一.主程用C++ 1.新建visu ...