swift 实践- 03 -- UILabel

class ViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

// 标签

let label: UILabel = UILabel(frame: CGRect(x: 100, y: 250, width: 200, height: 100))

label.text = "Hello world!"

self.view.addSubview(label)

label.textAlignment = .center

// 设置文本高亮

label.isHighlighted = true

// 设置文本高亮颜色

label.highlightedTextColor = UIColor.black

// 富文本设置

let attributeString = NSMutableAttributedString(string:"welcome to china")

// 改变指定位置的字符串的文字 font

attributeString.addAttribute(NSFontAttributeName,

value: UIFont.systemFont(ofSize: 20),

range: NSMakeRange(0, 4))

// 设置指定位置的字体颜色

attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.blue,

range: NSMakeRange(0, 3))

// 设置指定位置的文字背景颜色

attributeString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.green,

range: NSMakeRange(3,3))

label.attributedText = attributeString

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

时间: 2024-08-03 21:02:44

swift 实践- 03 -- UILabel的相关文章

使用Bootstrap 3开发响应式网站实践03,轮播下方的内容排版

通常把一些重要信息.需要重点标注的信息放在轮播的下方显示,这部分区域用到了大字体的标题.副标题以及段落文字等. <div class="row" id="bigCallout"> <div class="col-md-12"> <div class="well"> <div class="page-header"> <h1>梅西升腾小宇宙<s

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学习03

今天学习了Swift语言的以下内容(目录形式) 0.4. 面相对象 0.4.1. 构造函数基础 0.4.2. 重载构造函数 0.4.3. KVC 构造函数 0.4.4. 便利构造函数 0.4.5. 懒加载 0.4.6. 只读属性 0.5. 网络访问 0.6. 项目演练 0.6.1. 准备工作 0.6.2. 创建模型加载数据 0.6.3. 自定义 Cell

Swift 实践之UIWebView

1.选中工程,点击右键,New File>在iOS下选中Othe>Empty,生成一个.js的脚本文件,将代码粘贴过去保存; var script = document.createElement('script'); script.type = 'text/javascript'; script.text = ' function signin_go(){ location.href="ios:@signin_go"; } '; document.getElementsB

swift 实践- 13 -- UIStepper

import UIKit class ViewController: UIViewController { var stepper: UIStepper! var label: UILabel! override func viewDidLoad() { super.viewDidLoad() // 微调器 (UIStepper) 控件包含两个按钮 + ,-, 让使用者可以依照自己的喜欢做数值上的调整 stepper = UIStepper.init() stepper.center = sel

苹果官方Swift文档翻译03

转自:http://www.cnblogs.com/caios/p/3773680.html Welcome to Swift (苹果官方Swift文档初译与注解三)---11~18页 上述代码中,如果可选值为nil,那么判断条件则为false,而且在{}中的代码将会被忽略,如果可选值不为nil,会将该值逐步运算后赋值给let后面的常量,其中逐步运算过程将依据实际的代码块. Switch 语法支持任何类型数据以及各种比较操作,并不局限在整型. let vegetable = "red peppe

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 学习- 03 -- 基本运算符

// 运算符是检查,改变,合并值的特殊符号或短语, // swift 支持大部分标准的 C语言的运算符, 且改进许多特性来减少常规编码错误. /* 如: 赋值符 (=) 不返回值, 以防止把想要判断相等运算符 (==) 的地方写成 赋值符 导致的错误. 算数运算符 (+, -, * , / , %) 等 都会检测并不允许值溢出, 以此来避免保存变量是由于变量变大或小于其类型所能承载的范围导致的异常结果, 当然允许你使用 swift 的溢出运算符来实现溢出. swift 还提供 C语言没有的表达两

iOS实践03

主要目标:版本新特性界面,新浪授权界面(登录界面)的处理 任务基本完成了,基本的框架也就到这了,接下来的应该是首页获取微博了. 1.版本新特性,可以单独作为一个model,写完之加入到项目中.我们新建一个mvc方式的分组Newpart,主要应用的就是那个scrollview,有点类似于广告轮播,这个换成手动的切换图片. 2.在appdelegate中将window的根控制器换成newpartController,完成效果后在处理他们之间的逻辑. 3.添加UIScrollView来实现滚动,添加图