iOS开发 ----- UIButton
来源:互联网 发布:硬盘开盘数据恢复 编辑:程序博客网 时间:2024/06/07 03:03
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];
0 0
- UIButton-IOS开发
- iOS开发 UIButton专题
- iOS开发 : UIButton
- iOS开发-UIButton
- IOS开发之UIButton
- iOS开发API UIButton
- IOS开发之UIButton
- iOS开发 -- UIButton
- iOS开发 ----- UIButton
- iOS开发 UIButton 详解
- iOS - UIButton 开发总结
- iOS开发之UIButton
- iOS开发之UIButton
- iOS开发之UIButton
- UIButton按钮控件-iOS开发
- IOS开发之UIButton详解
- iOS 开发之设置UIButton
- iOS开发(3)UIButton
- 使用ViewFlipper+GestureDetector实现轮播图(APP引导页面)
- HDU 2669 Romantic (扩展欧几里得)
- 升级chrome出现SELinux问题的解决方法
- VS配置附加包含目录技巧
- Session数据的持久化读取实现原理
- iOS开发 ----- UIButton
- HDU 3018 Ant Trip(欧拉路径 + 并查集 + 连通性判断)
- 红黑树-Java版
- C库函数使用与总结之时间函数
- C库函数使用与总结之字符串处理函数
- 黑马程序员——Java之集合
- 算法基础之排序
- 字节序问题
- Source Insight常用功能设置