Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Swift UI之UILabel 和 UIButton(五)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

Swift_Demo https://github.com/Zhangjingwang1993/Swift.git UILabel func createSubviewsOfLabel() { // 创建Label, 之后设置frame let label = UILabel() label.frame = CGRectMake(10, 10

Swift_Demo https://github.com/Zhangjingwang1993/Swift.git

UILabel

func createSubviewsOfLabel()
    {
        // 创建Label,之后设置frame
        let label = UILabel()
        label.frame = CGRectMake(10,10,150,20)
        self.view.addSubview(label)


        let label1 = UILabel(frame: CGRectMake(10,50,20))
        self.view.addSubview(label1)

        // 属性的设置跟OC基本类似
        label.text = "This is a Label";
        label.textColor = UIColor.yellowColor()
        label.font = UIFont.systemFontOfSize(14)

        label1.backgroundColor = UIColor.clearColor()

        // 创建富文本
        let attrString = NSMutableAttributedString(string: "This is a attrString")

        // 设置字体的大小
        attrString.addAttribute(NSFontAttributeName,value: UIFont.systemFontOfSize(20),range: NSMakeRange(2,5))

        // 设置字体的颜色
        attrString.addAttribute(NSForegroundColorAttributeName,value: UIColor.redColor(),5))

        // 这只下划线
        attrString.addAttribute(NSUnderlineStyleAttributeName,value: NSUnderlineStyle.StyleSingle.rawValue,5))

        label1.attributedText = attrString
    }

UIButton

func createSubviewsOfButton()
    {
        // 创建
        let button = UIButton.init(type: UIButtonType.Custom)
        // 还可以这样 let button = UIButton(type: UIButtonType.Custom)
        button.frame = CGRectMake(10,80,50)
        button.backgroundColor = UIColor.greenColor()
        button.setTitle("iambutton",forState: UIControlState.Normal)
        button.addTarget(self,action: Selector("click:"),forControlEvents: UIControlEvents.TouchUpInside)
        button.layer.cornerRadius = 5
        self.view.addSubview(button)

    }

点击方法

func click(button:UIButton)
    {
        print("点击")
    }

大佬总结

以上是大佬教程为你收集整理的Swift UI之UILabel 和 UIButton(五)全部内容,希望文章能够帮你解决Swift UI之UILabel 和 UIButton(五)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:ui