iOS开发 ----- UIButton
2015-09-02 20:21
597 查看
UIButton
//创建 button 也可以用alloc init方式创建 button的类型为自定义类型 UIButton * button2 = [UIButton buttonWithType:UIButtonTypeCustom]; //初始化两张图片 UIImage * image = [UIImage imageNamed:@"1.png"]; UIImage * bgImage = [UIImage imageNamed:@"map.png"]; //设置button的前景图 [button2 setImage:image forState:UIControlStateNormal]; //设置button的背景图 [button2 setBackgroundImage:bgImage forState:UIControlStateNormal]; //设置button的位置大小 button2.frame = CGRectMake(0, 80, 375, 30); //设置点击的时候是否可以高亮 button2.showsTouchWhenHighlighted = YES; //添加到视图上 [self.view addSubview:button2]; //初始化button UIButton * button3 = [UIButton buttonWithType:UIButtonTypeCustom]; button3.frame = CGRectMake(0, 120, 375, 30); //设置button的标题 [button3 setTitle:@"按钮" forState:UIControlStateNormal]; //设置高亮时的标题 [button3 setTitle:@"llalala" forState:UIControlStateHighlighted]; //设置背景颜色 [button3 setBackgroundColor:[UIColor grayColor]]; //设置button的字体的颜色 [button3 setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal]; //设置button是否可用 button3.enabled = YES; //设置button的唯一标示符 button3.tag = 101; //button的点击方法 自己写onClick方法即可 [button3 addTarget:self action:@selector(onClick:)forControlEvents:UIControlEventTouchUpInside]; //其实button上边的字体相当于一个label,可以利用label的相关属性进行设置 //设置圆角矩形 button3.layer.cornerRadius = 10; //设置边框的颜色 button3.layer.borderColor = [UIColor grayColor].CGColor; //设置边框的宽度 button3.layer.borderWidth = 3; //设置button上的字体的大小 button3.titleLabel.font = [UIFont fontWithName:@"Menlo" size:30]; //设置字体的背景颜色 button3.titleLabel.backgroundColor = [UIColor redColor]; //设置 图片的位置 上左下右 button.imageEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 40); //设置 内容的位置 上左下右 button.contentEdgeInsets = UIEdgeInsetsMake(30, 10, 0, 0); //设置 文字的位置 上左下右 button.titleEdgeInsetsEdgeInsets = UIEdgeInsetsMake(30, 10, 0, 0); //把button添加到view上 [self.view addSubview:button3];
相关文章推荐
- iOS动画技术——ioS 7UIKit力学
- iOS开发中的UI所有知识点
- UIButtion解耦
- Android:Exported receiver does not require permission解决办法
- iOS开发 ----- UIImageView
- iOS开发 ----- UIView
- POJ 3061 Subsequence(二分/尺取法)
- 黑马程序员之GUI
- FMDB fmdb-master 在UI中使用OC语法对sqlate数据库处理
- easyUI的tree
- easyUI的tree
- 禁用mysql query cache
- IOS中UISearchController搜索框筛选功能实现
- mongo:Criteria和Query
- UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
- UISearchBar介绍
- UE4 FBX静态网格物体通道
- Arduino串口的正确打开方式
- iOS开发工具——Reveal:iOS的UI设计分析利器
- UIView详解