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 {

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值