Swift - 按钮(UIButton)的用法
来源:互联网 发布:网上兼职淘宝客服招聘 编辑:程序博客网 时间:2024/06/05 00:56
import UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // 创建一个ContactAdd类型的按钮 let button = UIButton(type: .ContactAdd) button.frame = CGRectMake(10, 150, 100, 30) button.setTitle("按钮", forState: UIControlState.Normal) self.view.addSubview(button) // 对于 Custom定制类型按钮,代码可以简化为 let btn = UIButton(frame: CGRectMake(10,200,100,30)) self.view.addSubview(btn) // 按钮文字设置 btn.setTitle("普通", forState: UIControlState.Normal) btn.setTitle("触摸", forState: UIControlState.Highlighted) btn.setTitle("禁用", forState: UIControlState.Disabled) // 按钮文字颜色设置 btn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal) // 按钮文字阴影颜色设置 btn.setTitleShadowColor(UIColor.grayColor(), forState: UIControlState.Normal) // 按钮背景颜色 btn.backgroundColor = UIColor.blueColor() // 按钮文字图标的设置 btn.setImage(UIImage(named: "icon1"), forState: UIControlState.Normal) btn.adjustsImageWhenHighlighted = false // 触摸按钮也不会变暗 btn.adjustsImageWhenDisabled = false // 禁用下按钮也不会变暗 // 设置按钮背景图片 btn.setBackgroundImage(UIImage(named: "background1"), forState: UIControlState.Normal) // 按钮触摸事件响应 btn.addTarget(self, action: #selector(tapped(_:)), forControlEvents: UIControlEvents.TouchUpInside) } /** 按钮触摸事件方法 */ func tapped(button:UIButton){ print(button.titleForState(UIControlState.Normal)) }}
0 0
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- iOS 【Swift - 按钮(UIButton)的用法】
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- swift 3.0 按钮的用法(UIButton)
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- swift-按钮(UIButton)用法
- Swift开发入门:按钮(UIButton)空间
- Swift-按钮(UIButton)详解
- Swift 按钮(UIButton)
- [leetcode] 139. Word Break
- haproxy 中的http请求和https请求
- 大失所望 果粉期待已久的iPhone7 原来就这样?
- mac下安装apktool
- Android使用上下文菜单ContextMenu
- Swift - 按钮(UIButton)的用法
- Java进阶(三十二) HttpClient使用详解
- Spring线程池
- 华为机试---搬圆桌
- zookeeper原理讲解(讲的很深奥不易懂 原理可以看上一篇 应用场景可以看看)
- Content-disposition中Attachment和inline的区别
- CAGradientLayer(颜色渐变) -- 实现iphone手机屏幕“滑动来解锁”动画效果
- android中Webview与javascript的交互(互相调用)
- 第十六周项目一(2)-小玩文件