ios11--UIButton
//
// ViewController.m
// 02-UIButton(在代码中使用)
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// 1.1 创建按钮对象
// UIButton *button = [[UIButton alloc] init];
// 注意:设置按钮的类型只能在初始化的时候设置 -> UIButtonTypeCustom
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; // 1.2 设置按钮的类型,是一个枚举,
//button.buttonType = UIButtonTypeInfoDark; // 1.3 设置frame
button.frame = CGRectMake(, , , ); // 1.4 设置背景颜色
// button.backgroundColor = [UIColor redColor];
// [button setBackgroundColor:[UIColor redColor]]; // 1.5 设置文字
// 分状态的:
// button.titleLabel.text = @"普通文字"; 显示不出来
[button setTitle:@"普通按钮" forState:UIControlStateNormal]; //正常显示的文字
[button setTitle:@"高亮按钮" forState:UIControlStateHighlighted];//点击时的文字 // 1.6 设置文字的颜色
[button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted]; // 1.7 设置文字的阴影颜色
[button setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateHighlighted]; button.titleLabel.shadowOffset = CGSizeMake(, ); // 1.8 设置内容图片,图片拖到Assets.xcassets右边里面去,
[button setImage:[UIImage imageNamed:@"player_btn_pause_normal"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"player_btn_pause_highlight"] forState:UIControlStateHighlighted]; button.imageView.backgroundColor = [UIColor purpleColor]; // 1.9 设置背景图片
[button setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted]; // 2.0 加到控制器的view中
[self.view addSubview:button]; // 非常重要
/**
* 监听按钮的点击事件,
* Target: 目标 (让谁做事情)
* action: 方法 (做什么事情-->方法)
* Events: 事件
*/
// SEL sel = @selector(clickButton:);
[button addTarget:self action:@selector(demo:) forControlEvents:UIControlEventTouchUpInside];
} - (void)demo:(UIButton *)btn{//btn就是按钮,
NSLog(@"%@", btn);
} - (IBAction)clickButton:(UIButton *)button {
button.enabled = NO;
} @end
ios11--UIButton的更多相关文章
- iOS11开发教程(二十三)iOS11应用视图实现按钮的响应(3)
iOS11开发教程(二十三)iOS11应用视图实现按钮的响应(3) 2.使用代码添加按钮实现的响应 使用代码添加的按钮,实现响应需要使用到addTarget(_:action:for:)方法,其语法形 ...
- iOS 11开发教程(十九)iOS11应用视图美化按钮之设置按钮的外观
iOS 11开发教程(十九)iOS11应用视图美化按钮之设置按钮的外观 美化按钮说白了就是对按钮的属性进行设置,设置按钮的属性有两种方法:一种是使用编辑界面中的属性检查器:另一种是使用代码进行设置.以 ...
- iOS 11开发教程(十八)iOS11应用视图之使用代码添加按钮
iOS 11开发教程(十八)iOS11应用视图之使用代码添加按钮 由于使用编辑界面添加视图的方式比较简单,所以不在介绍.这里,直接讲解代码中如何添加.使用代码为主视图添加一个按钮的方式和在1.3.3节 ...
- 针对Xcode 9 + iOS11 的修改,及iPhone X的适配
1,UIScrollView的automaticallyAdjustsScrollViewInsets 失效了. automaticallyAdjustsScrollViewInsets,当设置为YE ...
- iOS 11开发教程(十七)iOS11应用视图之使用按钮接收用户输入
iOS 11开发教程(十七)iOS11应用视图之使用按钮接收用户输入 在iOS中提供了很多的控件以及视图来丰富用户界面,对于这些视图以及控件我们在上一章中做了简单的介绍.本章我们将详细讲解这些视图. ...
- ios开发之--iOS 11适配:iOS11导航栏返回偏移
UIBarButtonItem 左边间隙过大,解决方案(ios11之前): 调用下面的方法,设置negativeSpacer.width = -15;就可以解决间隙过大的问题: UIBarButton ...
- iOS -- 解决iOS11中navigationBar上使用initWithCustomView按钮图片错位 frame无效
在iOS11上当使用如下代码设置时 UIButton *shareButton = [UIButton buttonWithType:(UIButtonTypeCustom)]; shareButto ...
- ios11返回按钮问题
在苹果系统升级到iOS11之后,页面的返回按钮的点击区域是根据设置的按钮的frame来确定的,在设置按钮太小的时候,点击就会出现点击多次才能点击到一次的现象,处理的方法就是设置按钮的frame变大代码 ...
- AFNetworking 3.0 源码解读(十一)之 UIButton/UIProgressView/UIWebView + AFNetworking
AFNetworking的源码解读马上就结束了,这一篇应该算是倒数第二篇,下一篇会是对AFNetworking中的技术点进行总结. 前言 上一篇我们总结了 UIActivityIndicatorVie ...
- 记录下UIButton的图文妙用和子控件的优先显示
UIButton的用处特别多,这里只记录下把按钮应用在图文显示的场景,和需要把图片作为按钮的背景图片显示场景: 另外记录下在父控件的子控件优先显示方法(控件置于最前面和置于最后面). 先上效果图: 1 ...
随机推荐
- swift 扩展 要素总结
类: 协议: 泛型及元素类型:扩展约束:
- Microsoft SQL Server Transact-SQL
Microsoft SQL Server Transact-SQL 1.SQL 1.1数据定义语言(DDL) create 创建数据库或数据库对象:alter 修改数据库或数据库对象:drop 删除数 ...
- 10Oracle Database 数据表数据查询
Oracle Database 数据表数据查询 DML 数据操纵语言 - 数据的查看和维护 select / insert /delete /update 基本查询语句 Select [distinc ...
- java.lang.NoSuchFieldError: DEFAULT_INCOMPATIBLE_IMPROVEMENTS
解决方案: 启动类上加@EnableAutoConfiguration(exclude = { FreeMarkerAutoConfiguration.class }) 或者在配置文件添加spring ...
- thymeleaf在开发环境正常,但用jar运行时报错 Error resolving template template might not exist or might not be accessible
解决方案: (1)配置中添加 spring.thymeleaf.prefix=classpath:/templates (2)指向模板的路径 不加 /
- HTML5大数据可视化效果(一)彩虹爆炸图
前言 25年过去了,Brooks博士著名的“没有银弹”的论断依旧没有被打破.HTML5也是一样.但这并不妨碍HTML5是一个越来越有威力的“炸蛋”:发展迅速.势不可挡.随着HTML5技术的普及,用HT ...
- 常用HTML5代码片段
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Grid Convergence Index-- Post Processing in CFD
t Grid Convergence Index Table of Contents 1. Grid/mesh independence GCI 1.1. Richardson extrapola ...
- Vuex实践小记
1.目录结构 2.开始(安装vuex) npm install vuex --save 3.编辑store/index.js(创建一个Vuex.store状态管理对象) import Vue from ...
- PAT 1127 ZigZagging on a Tree
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can ...