美文网首页iOS开发代码段
swift3.0-UI-1(Button+Label)实现基本交

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

作者: _弓长_大人 | 来源:发表于2016-11-27 19:44 被阅读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](https://img.haomeiwen.com/i2508221/62936c72200d1e24.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)](https://img.haomeiwen.com/i2508221/929cf846d5107e52.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

    相关文章

      网友评论

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

        本文链接:https://www.haomeiwen.com/subject/ymenpttx.html