swift-UILabel

 1 // Mark: 2. 创建label
 2     private func creatLabel(title: NSString)->UILabel{
 3                 /// 创建label
 4         let titleL = UILabel(frame: CGRectMake(100, 64, 200, 60))
 5
 6         titleL.text = title as String
 7         titleL.textColor = UIColor.redColor()
 8         titleL.backgroundColor = UIColor.yellowColor()
 9         titleL.layer.cornerRadius = 10.0
10         titleL.layer.masksToBounds = true
11         titleL.textAlignment = NSTextAlignment.Center
12         titleL.font = UIFont.systemFontOfSize(16.0)
13         // 阴影
14         titleL.shadowColor = UIColor.cyanColor()
15         titleL.shadowOffset = CGSizeMake(-2, 2)
16         // 省略方式
17         titleL.lineBreakMode = NSLineBreakMode.ByTruncatingTail
18 //        titleL.adjustsFontSizeToFitWidth = true
19         titleL.numberOfLines = 2
20
21         // 富文本
22         let attr = NSMutableAttributedString(string: "NSMutableAttributedStringNSMutableAttributedStringNSMutableAttributedString")
23
24         attr.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(25.0), range: NSMakeRange(0, 6))
25         attr.addAttribute(NSForegroundColorAttributeName, value: UIColor.purpleColor(), range: NSMakeRange(7, 15))
26         titleL.attributedText = attr
27
28         self.view.addSubview(titleL)
29         return titleL;
30     }
时间: 2024-11-14 11:21:17

swift-UILabel的相关文章

Swift UILabel 文字大小随着宽度调整

Swift UILabel的宽度一般都是固定的,但是文字有时候长有时候短,如何做到文字在超过Label宽度之后适当缩小使得现实完全 其实,很多简单 我们调用 adjustsFontSizeToFitWidth 即可实现 let label1=UILabel(frame: CGRectMake(30, 120, 300, 36)) label1.text="测试Swift UILabel 这里测试一下文字大小与标签宽度自适应 和设置最小缩放比例" self.view .addSubvie

swift UILabel多行显示时 计算UILable的高度(可用于UILable高度自适应)

代码如下 func heightForView(text:String, font:UIFont, width:CGFloat) -> CGFloat{ let label:UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: width, height: CGFloat.greatestFiniteMagnitude)) label.numberOfLines = 0 label.lineBreakMode = NSLineBreakMode.b

swift UILabel的高度自适应

let label = UILabel.init() label.backgroundColor = UIColor.grayColor() label.text = "1234567890-edfdgddffgfgfggfggddfbyfru6y6r7iuymgnjnrtfugyu57t6injyunjokn89uilmghbjl,hknjlllllllllllllllllllllllllllllllllllllmimomomkjnijunbuygbtyfrtdrxcresxweaswa&qu

Mac之button的使用Show+NSMenu+next+to+NSButton+in+Swift+OSX

http://www.itdaan.com/keywords/Show+NSMenu+next+to+NSButton+in+Swift+OSX.html http://www.itdaan.com/keywords/Swift+Mac+OSX+NSButton+title+color.html 1在SwiftOSX中显示NSButton旁边的NSMenu - ShowNSMenunext to NSButton in SwiftOSX 2016年04月11 - How can i show a

很好的iOS学习资料

https://github.com/vsouza/awesome-ios 汇集了很多好的资料 https://github.com/vsouza/awesome-ios Skip to content This repository Pull requests Issues Gist You don’t have any verified emails. We recommend verifying at least one email. Email verification helps ou

Swift - 通过叠加UILabel来实现混合的进度条

效果 源码 https://github.com/YouXianMing/Swift-Animations // // MixedColorProgressViewController.swift // Swift-Animations // // Created by YouXianMing on 16/8/21. // Copyright © 2016年 YouXianMing. All rights reserved. // import UIKit class MixedColorPro

Swift基础教程(swift代码创建第一个控件之UILabel)

首先 给需要创建的label 设置frame let textLabel = UILabel(frame:CGRectMake(self.view.frame.size.width/8,20,self.view.frame.size.width*3/4,100)) 给label 设值 textLabel.text = "现在我们来开始学习如何创建我们的第一个swift控件吧 -UILabel" 设置是否默认换行 textLabel.numberOfLines = 0 设置label的背

Swift基础教程(swift代码创建第一个控件之UILabel

创建视图的控件跟之前还是差不多,在viewdidload里面近些视图的创建. 首先 给需要创建的label 设置frame let textLabel = UILabel(frame:CGRectMake(self.view.frame.size.width/8,20,self.view.frame.size.width*3/4,100)) 给label 设值 textLabel.text = "现在我们来开始学习如何创建我们的第一个swift控件吧 -UILabel" 设置是否默认换

swift 动态设置UILabel的高度

import UIKit class ViewController3: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor=UIColor.whiteColor() var scrollView = UIScrollView(frame: CGRectMake(0, 0, ScreenWidth, ScreenHeight)) self.view.addSub

【Swift】UILabel的简单操作方法

@IBAction func buttonClick_LabelCtrl(sender: AnyObject) { //定义CGRect来初始化UILable var frame: CGRect = CGRect(x: 50, y: 50, width: 200, height: 200) var label: UILabel = UILabel(frame: frame) //获取和设置字体大小自适应属性(可以通过UIFont来设置字体) var adjuststate: Bool = lab