UILabel 属性

自学ios3个多月了,刚注册了博客,记录下学习过程。共勉,努力。


//
//  UILabel.h
//  UIKit
//
//  Copyright (c) 2006-2015 Apple Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import
<CoreGraphics/CoreGraphics.h>
#import
<UIKit/UIView.h>
#import
<UIKit/UIStringDrawing.h>
#import
<UIKit/UIKitDefines.h>

NS_ASSUME_NONNULL_BEGIN

@class UIColor,UIFont;

NS_CLASS_AVAILABLE_IOS(2_0)@interface UILabel :UIView <NSCoding>

//label文本     默认为空  设置label的文本.

/*

 竖排文字显示每个文字加一个换行符,这是最方便和简单的实现方式。

 label.text = @"\n\n\n\n\n\n";

 label.numberOfLines = [label.text length];

 */
@property ( nullable , nonatomic , copy )   NSString           *text;            // default is nil

//文字大小     默认字体大小为17
@property ( null_resettable , nonatomic , strong ) UIFont       *font;            // default is nil (system font 17 plain)

//文字颜色    默认为黑色
@property ( null_resettable , nonatomic , strong ) UIColor     *textColor;       // default is nil (text draws black)

//label的阴影颜色
@property ( nullable , nonatomic , strong ) 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

//设置文字过长时的显示格式

/*

 label.lineBreakMode = NSLineBreakByCharWrapping;以字符为显示单位显

 示,后面部分省略不显示。

 label.lineBreakMode = NSLineBreakByClipping;剪切与文本宽度相同的内

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

 label.lineBreakMode = NSLineBreakByTruncatingHead;前面部分文字

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

 label.lineBreakMode = NSLineBreakByTruncatingMiddle;中间的内容

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

 label.lineBreakMode = NSLineBreakByTruncatingTail;结尾部分的内容

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

 label.lineBreakMode = NSLineBreakByWordWrapping;以单词为显示单位显

 示,后面部分省略不显示。

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

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

//设置标签属性文本。

/*

 NSMutableAttributedString*attriString=[[NSMutableAttributedString alloc]initWithString:@"this is test!"];

 [attriString addAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} range:NSMakeRange(0, 4)];

 [attriString addAttributes:@{NSForegroundColorAttributeName:[UIColor greenColor]} range:NSMakeRange(8, 4)];

 //改变this的字体,value必须是一个CTFontRef

 [attriString addAttribute:(NSString *)kCTFontAttributeName

 value:(id)CFBridgingRelease(CTFontCreateWithName((CFStringRef)[UIFont boldSystemFontOfSize:14].fontName,14,NULL))range:NSMakeRange(0, 4)];

 //this加上下划线,value可以在指定的枚举中选择

 [attriString addAttribute:(NSString *)kCTUnderlineStyleAttributeName

 value:(id)[NSNumber numberWithInt:kCTUnderlineStyleDouble]

 range:NSMakeRange(0, 4)];

 UILabel*Label=[[UILabel alloc]initWithFrame:CGRectMake(100, 100, 200, 30)];

 Label.attributedText=attriString;

 [self.view addSubview:Label];

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

// 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 ( nullable , nonatomic , strong )               UIColor *highlightedTextColor; // default is nil

//是否显示高亮
@property(nonatomic,getter=isHighlighted)BOOL    highlighted;         // default is NO

//是否可以与用户交互
@property( nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled;

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

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

//标签最多显示行数,如果为0则表示多行。

@property( nonatomic) NSInteger numberOfLines;

//设置字体大小适应label宽度 

@property( nonatomic) BOOL adjustsFontSizeToFitWidth;

//如果adjustsFontSizeToFitWidth属性设置为YES,这个属性就来控制文本基线的行为。

/*

 UIBaselineAdjustmentAlignBaselines = 0,默认,文本最上端与中线对齐。

 UIBaselineAdjustmentAlignCenters,  文本中线与label中线对齐。

 UIBaselineAdjustmentNone, 文本最低端与label中线对齐。

 */

@property(nonatomic)UIBaselineAdjustment baselineAdjustment;

// 设置最小收缩比例,如果 Label 宽度小于文字长度时,文字进行收缩,收缩超过比例后,停止收缩。
@property(nonatomic)CGFloat minimumScaleFactorNS_AVAILABLE_IOS(6_0);// default is 0.0

// myLabel.allowsDefaultTighteningForTruncation = YES;这个属性是用来设置多行label的最大宽度的当自动布局的时候约束这个label的时候这个属性会起作用在自动布局添加约束中,若文本超过了指定的最大宽度的时候 文本会另起一行 从而增加了label的高度myLabel.preferredMaxLayoutWidth = 20;
@property ( nonatomic ) BOOL allowsDefaultTighteningForTruncation NS_AVAILABLE_IOS ( 9 _0); // default is NO
// 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);

/*
计算UIlabel 随字体多行后的高度
CGRect result,bounds;
bounds = CGRectMake(0, 0,200, 300);
heightLabel = [myLabel textRectForBounds:bounds limitedToNumberOfLines:20];//计算20行后的Label的Frame
NSLog(@"%f",heightLabel.size.height);
*/
- ( CGRect )textRectForBounds:( CGRect )bounds limitedToNumberOfLines:( NSInteger )numberOfLines;
   

//需要重载此方法,然后由子类调用,重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了
- ( void )drawTextInRect:( CGRect )rect;

// 设置最小收缩字号,如果 Label 宽度小于文字长度时,文字字号减小,低于设定字号后,不再减小。 6.0 以后不再使用了。
@property ( nonatomic ) CGFloat minimumFontSize NS_DEPRECATED_IOS ( 2 _0, 6 _0) __TVOS_PROHIBITED ; // deprecated - use minimumScaleFactor. default is 0.0

// 改变字母之间的间距来适应 Label 大小
@property(nonatomic)BOOL adjustsLetterSpacingToFitWidthNS_DEPRECATED_IOS(6_0,7_0)__TVOS_PROHIBITED;

@end

NS_ASSUME_NONNULL_END
                                                                                                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值