zoukankan      html  css  js  c++  java
  • 1_UILabel

    //
    //  ViewController.swift
    //  1_UILabel
    //
    //  Created by Larry on 2016/12/7.
    //  Copyright © 2016年 nfIOS. All rights reserved.
    
    
    import UIKit
    
    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
            let label = UILabel(frame: CGRect(x: 100, y: 100,  100, height: 100))
            //设置字体内容
            label.text = "larry111111111111"
            //设置字体颜色
            label.textColor = UIColor.orange
            //设置字体大小
            label.font = UIFont.boldSystemFont(ofSize: 34)
            //设置背景颜色
            label.backgroundColor = UIColor.blue
            //设置对齐方式
            label.textAlignment = .center
            //设置高亮模式(默认为false)
            label.isHighlighted = true
            //设置高亮模式下的字体颜色
            label.highlightedTextColor = UIColor.brown
            //超出label边界文字的截取方式
            label.lineBreakMode = .byClipping
            //是否能与用户交互(默认为false)
            label.isUserInteractionEnabled = true
            //设置文本文字自适应大小
            label.adjustsFontSizeToFitWidth = true
            //设置自动换行
            label.numberOfLines = 0
            //设置是否可改
            label.isEnabled = false
            //文本阴影颜色
            label.shadowColor = UIColor.darkGray
            //阴影大小
            label.shadowOffset = CGSize( 10, height: 10)
            //baselineAdjustment这个值控制文本的基线位置,只有文本行数为1是有效
            /*
             UIBaselineAdjustmentAlignBaselines = 0,默认,文本最上端与中线对齐。
             UIBaselineAdjustmentAlignCenters,  文本中线与label中线对齐。
             UIBaselineAdjustmentNone, 文本最低端与label中线对齐。
             */
            label.baselineAdjustment = .alignBaselines
            //minimumScaleFactor控制字体大小自适应(默认为0.0)
            //设置最小收缩比例,如果Label宽度小于文字长度时,文字进行收缩,收缩超过比例后,停止收缩。
            label.minimumScaleFactor = 0.5
            label.adjustsFontForContentSizeCategory = true
            label.allowsDefaultTighteningForTruncation = true
            
            self.view.addSubview(label)
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    
    }
  • 相关阅读:
    晋IT分享成长沙龙集锦
    Spring、Hibernate 数据不能插入到数据库问题解决
    fancybox关闭弹出窗体parent.$.fancybox.close();
    关于Javakeywordsynchronized——单例模式的思考
    MySQL Study之--MySQL压力測试工具mysqlslap
    cocos2d-x 3.3 之卡牌设计 NO.4 定时器的使用(清理内存)
    【v2.x OGE教程 16】 Modifier使用相关
    [Python网络编程]浅析守护进程后台任务的设计与实现
    hdu 4778 Gems Fight!
    nginx负载均衡向后台传递參数方法(后端也是nginxserver)
  • 原文地址:https://www.cnblogs.com/LarryBlogger/p/6143671.html
Copyright © 2011-2022 走看看