iOS开发代码段

swift3.0-UI-1(Button+Label)实现基本交

2016-11-27  本文已影响24人  _弓长_大人

选择 Single View Application模版swift语言 创建一个工程

在storyboard里拖两个 Button 按钮 和一个 label

屏幕快照 2016-11-27 下午7.33.14.png

将label 从storyboard拖到 实现文件 添加为输出接口
将两个 Button 拖到实现文件 添加 动作
使用 UIControlStatus.Normal 方法获取按钮标题

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var statusLabel: UILabel!
 
    @IBAction func buttonPressed(_ sender: UIButton) {
        let title=sender.title(for: .normal)!
        let plainText="\(title) button pressed"
        statusLabel.text=plainText
    }

}```

###四
实现点击不同的按钮,文本框出现不同的字


![
![屏幕快照 2016-11-27 下午7.42.52.png](http://upload-images.jianshu.io/upload_images/2508221-62936c72200d1e24.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)](http://upload-images.jianshu.io/upload_images/2508221-929cf846d5107e52.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
上一篇下一篇

猜你喜欢

热点阅读