iOS系列UI篇——UIButton
来源:互联网 发布:c语言为什么要指针 编辑:程序博客网 时间:2024/05/01 20:20
不说废话,直接上代码,温故而知新,确实受益良多!其中的奥妙,自己体会!
#import "ViewController.h"#define screen_width [UIScreen mainScreen].bounds.size.width#define screen_height [UIScreen mainScreen].bounds.size.height@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self createButton];}- (void)createButton{ float bw = 50; float bh = 50; //设置button的类型 /* UIButtonTypeCustom 自定 UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0) iOS7默认 UIButtonTypeDetailDisclosure 感叹号 UIButtonTypeInfoLight 感叹号 UIButtonTypeInfoDark 感叹号 UIButtonTypeContactAdd 加号 */ UIButton * b = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //设置frame值 b.frame = CGRectMake((screen_width - bw) / 2, (screen_height - bh) / 2, bw, bh); //设置背景色 b.backgroundColor = [UIColor redColor]; //设置按钮标题 [b setTitle:@"按钮" forState:(UIControlStateNormal)]; //设置按钮标题颜色 [b setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; //设置不同状态下文本阴影色 [b setTitleShadowColor:[UIColor orangeColor] forState:(UIControlStateNormal)]; //添加背景图片 [b setImage:[UIImage imageNamed:@"1.jpg"] forState:(UIControlStateNormal)]; //为button添加点击事件 [b addTarget:self action:@selector(buttonClicked:) forControlEvents:(UIControlEventTouchUpInside)]; //为button添加tag值 b.tag = 200; [self.view addSubview:b];}- (void)buttonClicked:(UIButton *)sender{ //设置背景图片 [sender setBackgroundImage:[UIImage imageNamed:@"1.jpg"] forState:(UIControlStateNormal)]; [sender setTitle:@"选中" forState:(UIControlStateSelected)]; sender.selected = YES;}
0 0
- iOS系列UI篇——UIButton
- iOS系列UI篇——自定义UIButton
- iOS开发之UI篇(7)—— UIButton
- iOS开发UI篇 -- UIButton
- iOS学习笔记(七)——UI基础UIButton
- iOS学习笔记(七)——UI基础UIButton
- iOS系列UI篇——UIControl
- iOS系列UI篇——UITextField
- iOS系列UI篇——UITextView
- ios系列UI篇——UISwitch
- iOS系列UI篇——UIImageView
- iOS系列UI篇——UIVisualEffectView
- iOS开发UI系列之UIButton的基本使用
- 自学iOS开发系列----UI(视图编程入门:UIButton)
- iOS开发UI技巧篇 -- UIButton
- iOS UI篇 学习笔记 UIButton,UIImageView
- IOS ui基础 uibutton
- IOS UI控件 - UIButton
- String类的常用方法
- Map与Map.Entry的关系
- Day_5面向对象
- Javascript继承的概念理解
- MySQL性能优化的最佳21条经验
- iOS系列UI篇——UIButton
- [移动与通讯]手机的军民两用
- 字符串类DP Align
- linux 基础
- vs 2010链接到Mysql数据库
- Volley 401 错误处理
- cocos2d-x c++使用误区记录
- 执行新程序 execve()
- SurfaceView的使用