美文网首页
iOS-OC-官方文档--UILabel属性和方法

iOS-OC-官方文档--UILabel属性和方法

作者: xiahua007 | 来源:发表于2016-03-03 11:02 被阅读413次

////  UILabel.h

//  UIKit

//

//  Copyright (c) 2006-2013, Apple Inc. All rights reserved.

// 

@class UIColor, UIFont; 

@class是放在interface中的,只是在引用一个类,将这个被引用类作为一个类型,在实现文件中,如果需要引用到被引用类的实体变量或者方法时,还需要使用#import方式引入被引用类。 

 NS_CLASS_AVAILABLE_IOS(2_0)

 @interface UILabel : UIView@property(nonatomic,copy)  NSString   *text;            // default is nil

设置此属性---将会在Label上显示文字,内容为text

@property(nonatomic,retain) UIFont   *font;            // default is nil (system font 17 plain)

设置此属性---改变text的大小,默认是17号

label.font = [UIFont systemFontOfSize:20]; //⼀一般方法

label.font = [UIFont boldSystemFontOfSize:20]; //加粗方法

label.font = [UIFont fontWithName:@"DBLCDTempBlack" size:25]; //指定字体和大小

@property(nonatomic,retain) UIColor   *textColor;      // default is nil (text draws black)

设置此属性---改变text的颜色,默认是黑色

@property(nonatomic,retain) UIColor      *shadowColor;    // default is nil (no shadow)

设置此属性---在text的后面添加阴影效果并设置颜色

@property(nonatomic)        CGSize     shadowOffset;    // default is CGSizeMake(0, -1) -- a top shadow

设置此属性---text的阴影与本身的位置偏差

@property(nonatomic)   NSTextAlignment    textAlignment;  // default is NSTextAlignmentLeft

NSTextAlignmentLeft—-靠左

NSTextAlignmentCenter –中间

NSTextAlignmentRight—靠右

设置此属性---text的对齐方式

@property(nonatomic)        NSLineBreakMode    lineBreakMode;  // default is NSLineBreakByTruncatingTail. used for single and multiple lines of text

设置此属性---text过长时的显示格式

NSLineBreakByCharWrapping;以字符为显示单位显示,后面部分省略不显示。

NSLineBreakByClipping;剪切与文本宽度相同的内

容长度,后半部分被删除。

NSLineBreakByTruncatingHead;前面部分文字

以……方式省略,显示尾部文字内容。

NSLineBreakByTruncatingMiddle;中间的内容

以……方式省略,显示头尾的文字内容。

NSLineBreakByTruncatingTail;结尾部分的内容

以……方式省略,显示头的文字内容。

NSLineBreakByWordWrapping;以单词为显示单位显示,后面部分省略不显示。

// the underlying attributed string drawn by the label, if set, the label ignores the properties above.

@property(nonatomic,copy)  NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0);  // default is nil

//attributedText:设置富文本。

NSString *text = @"XibHua";

NSMutableAttributedString *textLabelStr =[[NSMutableAttributedString alloc]initWithString:text];

[textLabelStr setAttributes:@{NSForegroundColorAttributeName :[UIColor orangeColor],NSFontAttributeName :[UIFont systemFontOfSize:17]} range:NSMakeRange(0,3)];

label.attributedText = textLabelStr;

显示结果为[XibHua]

// the 'highlight' property is used by subclasses for such things as pressed states. it's useful to make it part of the base class as a user property

@property(nonatomic,retain)              UIColor *highlightedTextColor; // default is nil

设置此属性---text高亮状态的字体颜色

@property(nonatomic,getter=isHighlighted) BOOL    highlighted;          // default is NO

设置此属性---text是否处于高亮

@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;  // default is NO

@property(nonatomic,getter=isEnabled)                BOOL enabled;

设置此属性---text 只是决定了Label的绘制方式,将它设置为NO将会使文本变暗,表示它没有激活,这时向它设置颜色值是无效的

// default is YES. changes how the label is drawn

// this determines the number of lines to draw and what to do when sizeToFit is called. default value is 1 (single line). A value of 0 means no limit

// if the height of the text reaches the # of lines or the height of the view is less than the # of lines allowed, the text will be

// truncated using the line break mode.

@property(nonatomic) NSInteger numberOfLines;

设置此属性---text最多显示行数,如果为0则表示多行

// these next 3 property allow the label to be autosized to fit a certain width by scaling the font size(s) by a scaling factor >= the minimum scaling factor

// and to specify how the text baseline moves when it needs to shrink the font.

@property(nonatomic) BOOL adjustsFontSizeToFitWidth;        // default is NO

未发现设置后的实际效果

@property(nonatomic) BOOL adjustsLetterSpacingToFitWidth NS_DEPRECATED_IOS(6_0,7_0); // deprecated - hand tune by using NSKernAttributeName to affect tracking

已经弃用,以后利用NSKernAttributeName来改变

@property(nonatomic) CGFloat minimumFontSize NS_DEPRECATED_IOS(2_0, 6_0); // NOTE: deprecated - use minimumScaleFactor. default is 0.0

已经弃用

@property(nonatomic) UIBaselineAdjustment baselineAdjustment; // default is UIBaselineAdjustmentAlignBaselines

未发现设置后的实际效果

@property(nonatomic) CGFloat minimumScaleFactor NS_AVAILABLE_IOS(6_0); // default is 0.0

// override points. can adjust rect before calling super.

// label has default content mode of UIViewContentModeRedraw

- (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines;

- (void)drawTextInRect:(CGRect)rect;

以上俩个方法一般用于重写Label.

// Support for constraint-based layout (auto layout)

// If nonzero, this is used when determining -intrinsicContentSize for multiline labels

@property(nonatomic) CGFloat preferredMaxLayoutWidth NS_AVAILABLE_IOS(6_0);

//到达此属性设置的宽度就换行

@end

相关文章

  • iOS-OC-官方文档--UILabel属性和方法

    //// UILabel.h // UIKit // // Copyright (c) 2006-2013, Ap...

  • Masonry

    Masonry Masonry常用的属性和方法 例: UILabel* lable = [[UILabel all...

  • 01 UIView 和 UILabel

    UIView和UILabel常用属性和常用方法总结 设置UILabel、UITextView的文字行间距 //MA...

  • label

    UILabel属性方法 1.初始化 UILabel * label = [...

  • Swift 4.0 属性(Properties)

    apple官方文档 懒加载 set 和get方法:set方法会有一个默认的newValue值 只读属性 观察者属性...

  • iOS Runtime经典面试题整理

    1,runtime 如何动态添加方法和属性和动态属性控制 通过苹果官方文档查看,我们可以发现runtime的内部存...

  • iOS笔记之UILabel(富文本)

    1、常见的属性及说明 2、常见方法: 更多方法和属性说明详见苹果官方说明文档。 3、使用示例: (1)、添加字体和...

  • UILabel

    UILabel:UIView UIView属性和方法UILabel都拥有作用是专门用来显示文字的控件 目录 la...

  • Swift-UIKit-UILabel

    1.描述 UILabel继承自UIView 苹果官方文档: A view that displays one or...

  • 2021-06-23

    UIlabel有一个属性叫preferredMaxLayoutWidth,官方解释是: // Support fo...

网友评论

      本文标题:iOS-OC-官方文档--UILabel属性和方法

      本文链接:https://www.haomeiwen.com/subject/jvonkttx.html