UIButton 的自定义创建
//iOS SDK 中的 UIButton 自定义创建
运行安装好的 xCode
选择: File->New Project.
从 'New Project' 窗口
选择 : iPhone OS ->Applications-> View-Based Application
命名 : 这里命名为 “Button”
//打开 ButtonViewController.m 文件: - (void)viewDidLoad { [super viewDidLoad]; //创建按钮 UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //设置按钮位置 [sampleButton setFrame:CGRectMake(10, 100, self.view.bounds.size.width- 20, 52)]; //定义按钮标题 [sampleButton setTitle:@"Button Title" forState:UIControlStateNormal]; //定义按钮标题字体格式 [sampleButton.titleLabel setFont:[UIFont boldSystemFontOfSize:20]]; //定义按钮背景图片,redButton.png已经存在,拖放添加图片文件到image项目文件夹中 [sampleButton setBackgroundImage:[[UIImage imageNamed:@"redButton.png"]stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateNormal]; //添加点击按钮所执行的程式 [sampleButton addTarget:self action:@selector(buttonClicked)forControlEvents:UIControlEventTouchUpInside]; //在 View 中加入按钮 [self.viewaddSubview:sampleButton]; } // -(void) buttonClicked { }