UILabel总结

UILabel

  • 能显示文字,不能直接通过addTarget...方法监听点击

1. 常见属性

  • @property(nonatomic,copy) NSString *text;

    • 显示文字
  • @property(nonatomic,retain) UIFont *font; + 显示字体 default is nil (system font 17 plain)
  • @property(nonatomic,retain) UIColor *textColor;
    • 文字颜色 default is nil (text draws black)
  • @property(nonatomic,retain) UIColor *shadowColor;
    • 阴影 default is nil (no shadow)
  • @property(nonatomic) CGSize shadowOffset;
    • 阴影位置 default is CGSizeMake(0, -1) -- a top shadow
  • @property(nonatomic) NSTextAlignment textAlignment;
    • 文字对齐模式 default is NSTextAlignmentLeft
  • @property(nonatomic) NSLineBreakMode lineBreakMode;
    • 换行模式
  • @property(nonatomic) NSInteger numberOfLines;
    • 文字行数
  • lineBreakMode
    • 内容缩进模式

2. UIFont

  • UIFont代表字体,常见创建方法有以下几个:

    • (UIFont *)systemFontOfSize:(CGFloat)fontSize; 系统默认字体
    • (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize; 粗体
    • (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; 斜体
  • 要想让UILabel自动换行,设置Lines为0即可
时间: 2024-08-06 11:15:15

UILabel总结的相关文章

ios 根据文字数量计算UILabel高度

以前封装过多个关于实现此功能的方法,虽然都实现了效果,但代码和实现思路都相对复杂很多,而且并不比我下面要说的这个方法好,这个也是我今天突发奇想来的,测量一下字体的宽度,然后根据这个点来计算 UILabel高度.这里我使用的FontSize是13,我测出它的高度.宽度都是15像素,如果你使用其他号字体,需要自己从新测下字体宽度.高度,下面贴出代码. 一.实现代码 //申明时的label的高度可以随便设置,因为之后计算出高度后还需要从设置一次 UILabel *label = [[UILabel a

iOS7中计算UILabel中字符串的高度

iOS7中出现了新的方法计算UILabel中根据给定的Font以及str计算UILabel的frameSize的方法.本人提供category如下: UILabel+StringFrame.h ////  UILabel+StringFrame.h//  LabelHeight////  Copyright (c) 2014年 Y.X. All rights reserved.//#import <UIKit/UIKit.h>@interface UILabel (StringFrame)- 

ios设置UILabel中文字的不同颜色和字体字号

参考博客:http://blog.csdn.net/woaifen3344/article/details/38352099    http://www.cnblogs.com/whyandinside/archive/2013/12/27/3493475.html 要使UILabel显示不同的字体,需要设置其 attributedText属性 该属性是NSMutableAttributedString/NSAttributedString类型; NSAttributedString是一个带有属

iOS开发-UI (一)补充 UIWindow UIView UIlabel

之前忘了把这些整理出来,现在补充一下,应该放在前面学习的 知识点: 1.UI的初步认识 2.UIWindow 3.UIView 4.UIlabel ======================== UI的初步认识 1.什么是UI(*) UI即User Interface(用户界面)的简称.UI设计则是指对软 件的人机交互.操作逻辑.界面美观的整体设计.好的UI设 计不仅是让软件变得有个性有品味,还要让软件的操作变得 舒适.简单.自由.充分体现软件的定位和特点. 2.第一个UI工程 1)UI工程的

iOS学习笔记 25:UILabel 的一个蛋疼问题

问题描述 在iOS8以下版本,numberOfLines设置为0,编译警告Automatic Preferred Max Layout Width before iOS8.0,同时不能换行. 问题分析 iOS8以下版本,要 UILabel 行数大于0,单numberOfLines设置为0是不行的,还需要指定 preferredMaxLayoutWidth,告诉UILabel折行的位置.这个问题到 iOS8 就不存在了,不需要设置preferredMaxLayoutWidth. 问题解决 如果用到

关于UITextFiled,UIlabel,UIBUtton相关设置,边框设置和字体设置

设置账号,密码字体的颜色 NSMutableDictionary *dict = [NSMutableDictionary dictionary]; dict[NSForegroundColorAttributeName] = [ICETools colorWithHexString:@"C1C0C2"]; NSAttributedString *attribute = [[NSAttributedString alloc] initWithString:self.accountTex

封装一个UILabel圆形边框显示进度

封装了一个UILabel并让它显示圆形的边框,UILabel上面显示百份比,而边框则用Animation绘制到整个圆占指定百分比的点. 这只是我个人想的继承一个UILabel实现的,用到两个CAShapeLayer,第一个Layer的作用是画出灰色的背影圆圈,第二个Layer位置放置在第一个Layer的上面,并设置为红色描绘颜色并描绘到插定的位置,之后实现相应的动画效果即可. import UIKit class kCircleLabel: UILabel { var percent:Doubl

UILabel(label控件)的详细使用及特殊效果

转自:http://blog.sina.com.cn/s/blog_af73e7a70101ahlm.html UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(0, 0, 75, 40)];   //声明UIlbel并指定其位置和长宽 label.backgroundColor = [UIColorclearColor];   //设置label的背景色,这里设置为透明色. label.font = [UIFont fontWi

iOS UILabel 设置行高

UILabel *tileLabel = [[UILabel alloc] init]; tileLabel.numberOfLines = 0; tileLabel.backgroundColor = [UIColor clearColor]; tileLabel.text = @"调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整

UILabel的使用

常用属性UILabel //显示的文字 @property(nonatomic,copy)   NSString           *text; //字体 @property(nonatomic,retain) UIFont             *font; //文字颜色 @property(nonatomic,retain) UIColor            *textColor; //对齐模式(比如左对齐.居中对齐.右对齐) @property(nonatomic)