iOS开发 UIButton的创建与使用

2025-06-05 10:57:43

1、创建工程项目和视图控制器 1、创建一个Sing View Application工程项目; 2、为项目命名,生成工程文件。

iOS开发 UIButton的创建与使用

3、设置位置和使能 [button setFrame:CGRectMake(16, 30, 200, 50)]; [button setCenter:self.view.center]; [button setEnabled:YES];

iOS开发 UIButton的创建与使用

5、设置圆角/边框 [button.layer setCornerRadius:5.0]; [button.layer setMasksToBounds:YES]; [button.layer setBorderWidth:3.0]; [button.layer setBorderColor:[[UIColor redColor] CGColor]];

iOS开发 UIButton的创建与使用

7、设置图标 默认30*30大小的。@2x为60*60;@3x为90*90的。

iOS开发 UIButton的创建与使用

9、添加目标动作响应 [button addTarget:self action:@selector(holdDown蚱澄堆别ButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];- (void)holdDownButtonTouchUpInside:(UIButton *)sender{ NSLog(@"按住按钮触摸到里面");}

iOS开发 UIButton的创建与使用
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢