Swift UILabel的使用

2024-05-31 06:32
文章标签 使用 swift uilabel

本文主要是介绍Swift UILabel的使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.新建Swift IOS app空项目





加入代码

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. //  
  2. //  AppDelegate.swift  
  3. //  UILableDemo  
  4. //  
  5. //  Created by 赵超 on 14-6-17.  
  6. //  Copyright (c) 2014年 赵超. All rights reserved.  
  7. //  
  8.   
  9. import UIKit  
  10.   
  11. @UIApplicationMain  
  12. class AppDelegate: UIResponder, UIApplicationDelegate {  
  13.       
  14.     var window: UIWindow?  
  15.     var label:UILabel?  
  16.   
  17.     func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {  
  18.         self.window = UIWindow(frame: UIScreen.mainScreen().bounds)  
  19.         // Override point for customization after application launch.  
  20.         self.window!.backgroundColor = UIColor.grayColor()  
  21.         self.window!.makeKeyAndVisible()  
  22.         //初始化UILabel  
  23.         label=UILabel()  
  24.         //label大小  
  25.         label!.frame = CGRect(x:50, y:100, width:200, height:100)  
  26.         label!.text = "Hello Swift"  
  27.         //背影色  
  28.         label!.backgroundColor=UIColor.blueColor()  
  29.         //对齐  
  30.         label!.textAlignment=NSTextAlignment.Center  
  31.         //字体  
  32.         label!.font=UIFont(name:"Thonburi",size:30)  
  33.         //Gray  
  34.         var labColor=UIColor(white:1,alpha:1);  
  35.         //RGB  
  36.         labColor=UIColor(red:255,green:255,blue:0,alpha:1)  
  37.         //系统色  
  38.         labColor=UIColor.lightTextColor()  
  39.         //静态色  
  40.         labColor=UIColor.redColor();  
  41.         label!.textColor=labColor  
  42.           
  43.         self.window!.addSubview(label)  
  44.         return true  
  45.     }  
  46.   
  47.     func applicationWillResignActive(application: UIApplication) {  
  48.         // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.  
  49.         // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.  
  50.     }  
  51.   
  52.     func applicationDidEnterBackground(application: UIApplication) {  
  53.         // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.  
  54.         // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.  
  55.     }  
  56.   
  57.     func applicationWillEnterForeground(application: UIApplication) {  
  58.         // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.  
  59.     }  
  60.   
  61.     func applicationDidBecomeActive(application: UIApplication) {  
  62.         // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.  
  63.     }  
  64.   
  65.     func applicationWillTerminate(application: UIApplication) {  
  66.         // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.  
  67.     }  
  68.   
  69.   
  70. }  

效果图



这篇关于Swift UILabel的使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/1017504

相关文章

python中的显式声明类型参数使用方式

《python中的显式声明类型参数使用方式》文章探讨了Python3.10+版本中类型注解的使用,指出FastAPI官方示例强调显式声明参数类型,通过|操作符替代Union/Optional,可提升代... 目录背景python函数显式声明的类型汇总基本类型集合类型Optional and Union(py

Java使用正则提取字符串中的内容的详细步骤

《Java使用正则提取字符串中的内容的详细步骤》:本文主要介绍Java中使用正则表达式提取字符串内容的方法,通过Pattern和Matcher类实现,涵盖编译正则、查找匹配、分组捕获、数字与邮箱提... 目录1. 基础流程2. 关键方法说明3. 常见场景示例场景1:提取所有数字场景2:提取邮箱地址4. 高级

使用SpringBoot+InfluxDB实现高效数据存储与查询

《使用SpringBoot+InfluxDB实现高效数据存储与查询》InfluxDB是一个开源的时间序列数据库,特别适合处理带有时间戳的监控数据、指标数据等,下面详细介绍如何在SpringBoot项目... 目录1、项目介绍2、 InfluxDB 介绍3、Spring Boot 配置 InfluxDB4、I

使用Java读取本地文件并转换为MultipartFile对象的方法

《使用Java读取本地文件并转换为MultipartFile对象的方法》在许多JavaWeb应用中,我们经常会遇到将本地文件上传至服务器或其他系统的需求,在这种场景下,MultipartFile对象非... 目录1. 基本需求2. 自定义 MultipartFile 类3. 实现代码4. 代码解析5. 自定

使用Python实现无损放大图片功能

《使用Python实现无损放大图片功能》本文介绍了如何使用Python的Pillow库进行无损图片放大,区分了JPEG和PNG格式在放大过程中的特点,并给出了示例代码,JPEG格式可能受压缩影响,需先... 目录一、什么是无损放大?二、实现方法步骤1:读取图片步骤2:无损放大图片步骤3:保存图片三、示php

使用Python实现一个简易计算器的新手指南

《使用Python实现一个简易计算器的新手指南》计算器是编程入门的经典项目,它涵盖了变量、输入输出、条件判断等核心编程概念,通过这个小项目,可以快速掌握Python的基础语法,并为后续更复杂的项目打下... 目录准备工作基础概念解析分步实现计算器第一步:获取用户输入第二步:实现基本运算第三步:显示计算结果进

python之uv使用详解

《python之uv使用详解》文章介绍uv在Ubuntu上用于Python项目管理,涵盖安装、初始化、依赖管理、运行调试及Docker应用,强调CI中使用--locked确保依赖一致性... 目录安装与更新standalonepip 安装创建php以及初始化项目依赖管理uv run直接在命令行运行pytho

C#使用Spire.XLS快速生成多表格Excel文件

《C#使用Spire.XLS快速生成多表格Excel文件》在日常开发中,我们经常需要将业务数据导出为结构清晰的Excel文件,本文将手把手教你使用Spire.XLS这个强大的.NET组件,只需几行C#... 目录一、Spire.XLS核心优势清单1.1 性能碾压:从3秒到0.5秒的质变1.2 批量操作的优雅

Kotlin 枚举类使用举例

《Kotlin枚举类使用举例》枚举类(EnumClasses)是Kotlin中用于定义固定集合值的特殊类,它表示一组命名的常量,每个枚举常量都是该类的单例实例,接下来通过本文给大家介绍Kotl... 目录一、编程枚举类核心概念二、基础语法与特性1. 基本定义2. 带参数的枚举3. 实现接口4. 内置属性三、

Java List 使用举例(从入门到精通)

《JavaList使用举例(从入门到精通)》本文系统讲解JavaList,涵盖基础概念、核心特性、常用实现(如ArrayList、LinkedList)及性能对比,介绍创建、操作、遍历方法,结合实... 目录一、List 基础概念1.1 什么是 List?1.2 List 的核心特性1.3 List 家族成