当前位置:网站首页>[OC]-<UI入门>--常用控件的学习
[OC]-<UI入门>--常用控件的学习
2022-07-06 08:50:00 【关于小司】
UILabel
UI
UI就是用户界面
“UI就是User Interface的所写,也就是用户界面。UI设计就是用户界面设计,界面则主要包括移动端(Android和IOS),PC端,Dashboard。
UILabel是什么
UILabel 是一个可以显示在屏幕上,并且可以显示文字的一种UI视图
创建并使用一个 UILabel
- 我们打开Xcode 选择App开发 找到 ViewController 在 实现部分添加创建UILabel的函数

- 定义创建一个UILable对象
- 显示文字赋值,txt是字符串对象
UILabel* label = [[UILabel alloc]init];
//显示文字赋值,txt是字符串对象
label.text = @"Hello myiOSxxxxxxxxxx";
1)label初级属性
- 设置label显示位置 frame属性
- CGRectMake(100, 300, 160, 200);
注意前两个数字代表了初始坐标原点 后面的数字代表了向右下方延展 与x y轴的距离
//设置label显示位置
//100x-距离左边,100y距离边矩形左上角位置 160-宽 40-高
label.frame = CGRectMake(100, 300, 160, 200);
- 设置背景颜色
label.backgroundColor = [UIColor grayColor];// 有背景颜色
label.backgroundColor = [UIColor clearColor]; //透明颜色颜色
- 这个背景颜色指的是我们文字显示的颜色,后面还会有文字颜色
- 整个背景颜色的设置
整个背景颜色的设置
self.view.backgroundColor = [UIColor whiteColor];
- 将label显示到屏幕上-
将label显示到屏幕上
[self.view addSubview:label];
- 设置label文字大小
- 设置文字颜色
//设置label文字大小
//systemFontOfSize 系统默认字体 大小12
label.font = [UIFont systemFontOfSize:24];
//设置文字颜色
label.textColor = [UIColor blackColor];
2)label高级属性
设定阴影颜色
设置阴影的偏移位置x-横向偏移, y:纵向偏移向下的距离
CGSizeMake(10, 10);设置文字对齐–textAlignment
label文字显示行数 ,默认一行
其他的大于0的行数文字 尽量显示
如果label.numberOfLines = 0,iOS会对文字自动计算需要行数,按照需要来显示
//设定阴影颜色
label.shadowColor = [UIColor blueColor];
//设置阴影的偏移位置x-横向偏移, y:纵向偏移向下的距离
label.shadowOffset = CGSizeMake(10, 10);
//设置文字对齐--textAlignment
// 默认左对齐
label.textAlignment = NSTextAlignmentCenter ;
//设定label文字显示行数 ,默认一行
//其他的大于0的行数文字 尽量显示
//如果label.numberOfLines = 0,iOS会对文字自动计算需要行数,按照需要来显示
label.numberOfLines = 0 ;
怎么看效果
打开Xcode 在最上面选择虚拟机

使用command+r 运行

这就是我们的第一个UILabel界面-- 我们使得
label.numberOfLines = 0 ;
这样系统会自动根据我们的紫薯找出需要的位置
关于几个颜色
label.backgroundColor = [UIColor grayColor];// 有背景颜色
label.backgroundColor = [UIColor clearColor]; //透明颜色颜色
当我们把这两个都写上的时候系统会默认执行透明而不是灰色 ,所以我们需要透明的时候再写 一半还是我们自己设置颜色
整个背景颜色的设置
self.view.backgroundColor = [UIColor whiteColor];是整个背景窗口都是白色
字体和阴影颜色
label.textColor = [UIColor blackColor];
label.shadowColor = [UIColor blueColor];
注意设置阴影部分 和文字尽量不要重叠
边栏推荐
- Revit secondary development Hof method calls transaction
- LeetCode:387. 字符串中的第一个唯一字符
- LeetCode:214. 最短回文串
- UML圖記憶技巧
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Super efficient! The secret of swagger Yapi
- Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
- To effectively improve the quality of software products, find a third-party software evaluation organization
- ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
猜你喜欢

UML图记忆技巧

Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)

【嵌入式】Cortex M4F DSP库

MongoDB 的安装和基本操作

Double pointeur en langage C - - modèle classique

ROS compilation calls the third-party dynamic library (xxx.so)

查看局域网中电脑设备

企微服务商平台收费接口对接教程

Crash problem of Chrome browser

Esp8266-rtos IOT development
随机推荐
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
LeetCode:41. Missing first positive number
Using C language to complete a simple calculator (function pointer array and callback function)
LeetCode:剑指 Offer 48. 最长不含重复字符的子字符串
Tdengine biweekly selection of community issues | phase III
Computer cleaning, deleted system files
数学建模2004B题(输电问题)
opencv+dlib实现给蒙娜丽莎“配”眼镜
Revit 二次开发 HOF 方式调用transaction
Export IEEE document format using latex
广州推进儿童友好城市建设,将探索学校周边200米设安全区域
UnsupportedOperationException异常
The network model established by torch is displayed by torch viz
企微服务商平台收费接口对接教程
查看局域网中电脑设备
LeetCode:34. 在排序数组中查找元素的第一个和最后一个位置
pytorch查看张量占用内存大小
MYSQL卸载方法与安装方法
Image, CV2 read the conversion and size resize change of numpy array of pictures